文字上、下标
# 上标——以想要在横轴上添加"Observed LE(W/m-2)"为例
ax.set_xlabel('Observed LE(W/$\mathdefault{m^2}$)', fontsize=12)
# 或者是
ax.set_xlabel('Observed LE(W/${m^{2}}$)', fontsize=12)
# 下标——以想要在横轴上添加"LEi"为例
ax.set_xlabel('$\mathdefault{LE_i}$', fontsize=12)
统一全局字体
# 在绘图之前,设置图形参数,绘图时则默认使用
params = {
'axes.labelsize': '20', #轴上字
'xtick.labelsize':'16', #轴图例
'ytick.labelsize':'16', #轴图例
'lines.linewidth': "1.2", # 线宽
'legend.fontsize': '16', #图例大小
'figure.figsize': '12, 8', # set figure size,长12,宽9
'font.weight': 'bold'
}
pylab.rcParams.update(params) # set figure parameter
mpl.rcParams['font.sans-serif'] = ["Times New Roman"]
图像输出范围控制:bbox_inches='tight'
# 保证图像输出合适范围——bbox_inches='tight'
plt.savefig(outpath, dpi=400, bbox_inches='tight') # tight设置是让图片裁剪的刚刚好
子图共享x/y轴
# 子图共享x/y轴
axs = gs.subplots(sharex=True, sharey=True)
# 子图共享x轴,y轴同理
axs = gs.subplots(sharex=True)
创建子图的两种种方式
# 第一种gridspec.GridSpec
gs = gridspec.GridSpec(2, 2) # 创立2 * 2 网格
gs.update(wspace=0.2, hspace=0.3) # 间隙
#第一行
ax1 = plt.subplot(gs[0, 0]) # gs(哪一行,绘制网格列的范围)
ax2 = plt.subplot(gs[0, 1])
# 对第二行进行绘制
ax3 = plt.subplot(gs[1, 0])
ax4 = plt.subplot(gs[1, 1])
# 第二种fig.add_gridspec
fig = plt.figure(dpi=600)
# 布局,2行,1列
gs = fig.add_gridspec(2, 1)
# 共享x、y轴
axs = gs.subplots(sharex=True, sharey=True)
# 绘制时直接
axs[0][0].bar(x_num_list, Es_sites1, label='$\mathdefault{LE_s}$', color=(253/255, 209/255, 113/255))
axs[0][1].bar(x_num_list, Ec_sites1, bottom=Es_sites1, label='$\mathdefault{LE_c}$', color=(134/255, 199/255, 190/255))
.............