python作图(Matplotlib: Visualization with Python)
程序员文章站
2024-03-26 12:46:17
...
直方图
axs.hist(x, bins=n_bins)
# bins:间隔数量
组合图表显示
axs = plt.figure(figsize=figsize, constrained_layout=True).subplots(rows, cols)
中文显示错误
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
保留指定位数的小数
format(number, '.3f')
常用字体及相关参数
families = ['serif', 'sans-serif', 'cursive', 'fantasy', 'monospace']
alignment = {'horizontalalignment': 'center', 'verticalalignment': 'baseline'}
t = plt.figtext(0.1, 0.9, 'family', size='large', **alignment)
styles = ['normal', 'italic', 'oblique']
weights = ['light', 'normal', 'medium', 'semibold', 'bold', 'heavy', 'black']
sizes = ['xx-small', 'x-small', 'small', 'medium', 'large',
'x-large', 'xx-large']
参考:
官网教程:https://matplotlib.org/