Python - 颜色条的标签大小
Python - Label size of colorbar
我想缩小不同颜色条的标签大小。
目前我有照片,你可以在下面看到。我在 plt.colorbar 中尝试 "labelsize" 但它不起作用
我的代码是:
plt.close()
fig, axes = plt.subplots(nrows=1, ncols=3)
plt.tight_layout(pad=0.05, w_pad=0.001, h_pad=2.0)
ax1 = plt.subplot(131) # creates first axis
ax1.set_xticks([0,2000,500,1000,1500])
ax1.set_yticks([0,2000,500,1000,1500])
ax1.tick_params(labelsize=8)
i1 = ax1.imshow(U,cmap='hot',extent=(X.min(),2000,Y.min(),2000))
plt.colorbar(i1,ax=ax1,ticks=[U.min(),(U.min()+U.max())/2., U.max()],fraction=0.046, pad=0.04,format='%.2f')
ax1.set_title("$ \mathrm{Ux_{mes} \/ (pix)}$", y=1.05, fontsize=12)
ax2 = plt.subplot(132) # creates second axis
ax2.set_xticks([0,2000,500,1000,1500])
ax2.set_yticks([0,2000,500,1000,1500])
i2=ax2.imshow(UU,cmap='hot',extent=(X.min(),2000,Y.min(),2000))
ax2.set_title("$\mathrm{Ux_{cal} \/ (pix)}$", y=1.05, fontsize=12)
ax2.set_xticklabels([])
ax2.set_yticklabels([])
plt.colorbar(i2,ax=ax2,fraction=0.046, pad=0.04,ticks=[UU.min(),(UU.min()+UU.max())/2.,UU.max()],format='%.2f')
ax3 = plt.subplot(133) # creates first axis
ax3.set_xticks([0,2000,500,1000,1500])
ax3.set_yticks([0,2000,500,1000,1500])
i3 = ax3.imshow(resU,cmap='hot',extent=(X.min(),2000,Y.min(),2000))
ax3.set_title("$\mathrm{\mid Ux_{mes} - Ux_{cal} \mid \/ (pix)}$ ", y=1.05, fontsize=12)
plt.colorbar(i3,ax=ax3,fraction=0.046, pad=0.04,ticks=[resU.min(), (resU.min()+resU.max())/2.,resU.max()],format='%.2f')
ax3.set_xticklabels([])
ax3.set_yticklabels([])
plt.gcf().tight_layout()
plt.savefig('test.eps', format='eps', dpi=1000, bbox_inches='tight', pad_inches=0.1)
#plt.show()
如图in this answer,如果你命名你的颜色条(这里我使用cb1,cb2,cb3
),你可以这样设置刻度参数:
cb1=plt.colorbar(i1,ax=ax1,ticks=[U.min(),(U.min()+U.max())/2., U.max()],fraction=0.046, pad=0.04,format='%.2f')
cb2=plt.colorbar(i2,ax=ax2,fraction=0.046, pad=0.04,ticks=[UU.min(),(UU.min()+UU.max())/2.,UU.max()],format='%.2f')
cb3=plt.colorbar(i3,ax=ax3,fraction=0.046, pad=0.04,ticks=[resU.min(), (resU.min()+resU.max())/2.,resU.max()],format='%.2f')
cb1.ax.tick_params(labelsize=6)
cb2.ax.tick_params(labelsize=6)
cb3.ax.tick_params(labelsize=6)
我想缩小不同颜色条的标签大小。 目前我有照片,你可以在下面看到。我在 plt.colorbar 中尝试 "labelsize" 但它不起作用
我的代码是:
plt.close()
fig, axes = plt.subplots(nrows=1, ncols=3)
plt.tight_layout(pad=0.05, w_pad=0.001, h_pad=2.0)
ax1 = plt.subplot(131) # creates first axis
ax1.set_xticks([0,2000,500,1000,1500])
ax1.set_yticks([0,2000,500,1000,1500])
ax1.tick_params(labelsize=8)
i1 = ax1.imshow(U,cmap='hot',extent=(X.min(),2000,Y.min(),2000))
plt.colorbar(i1,ax=ax1,ticks=[U.min(),(U.min()+U.max())/2., U.max()],fraction=0.046, pad=0.04,format='%.2f')
ax1.set_title("$ \mathrm{Ux_{mes} \/ (pix)}$", y=1.05, fontsize=12)
ax2 = plt.subplot(132) # creates second axis
ax2.set_xticks([0,2000,500,1000,1500])
ax2.set_yticks([0,2000,500,1000,1500])
i2=ax2.imshow(UU,cmap='hot',extent=(X.min(),2000,Y.min(),2000))
ax2.set_title("$\mathrm{Ux_{cal} \/ (pix)}$", y=1.05, fontsize=12)
ax2.set_xticklabels([])
ax2.set_yticklabels([])
plt.colorbar(i2,ax=ax2,fraction=0.046, pad=0.04,ticks=[UU.min(),(UU.min()+UU.max())/2.,UU.max()],format='%.2f')
ax3 = plt.subplot(133) # creates first axis
ax3.set_xticks([0,2000,500,1000,1500])
ax3.set_yticks([0,2000,500,1000,1500])
i3 = ax3.imshow(resU,cmap='hot',extent=(X.min(),2000,Y.min(),2000))
ax3.set_title("$\mathrm{\mid Ux_{mes} - Ux_{cal} \mid \/ (pix)}$ ", y=1.05, fontsize=12)
plt.colorbar(i3,ax=ax3,fraction=0.046, pad=0.04,ticks=[resU.min(), (resU.min()+resU.max())/2.,resU.max()],format='%.2f')
ax3.set_xticklabels([])
ax3.set_yticklabels([])
plt.gcf().tight_layout()
plt.savefig('test.eps', format='eps', dpi=1000, bbox_inches='tight', pad_inches=0.1)
#plt.show()
如图in this answer,如果你命名你的颜色条(这里我使用cb1,cb2,cb3
),你可以这样设置刻度参数:
cb1=plt.colorbar(i1,ax=ax1,ticks=[U.min(),(U.min()+U.max())/2., U.max()],fraction=0.046, pad=0.04,format='%.2f')
cb2=plt.colorbar(i2,ax=ax2,fraction=0.046, pad=0.04,ticks=[UU.min(),(UU.min()+UU.max())/2.,UU.max()],format='%.2f')
cb3=plt.colorbar(i3,ax=ax3,fraction=0.046, pad=0.04,ticks=[resU.min(), (resU.min()+resU.max())/2.,resU.max()],format='%.2f')
cb1.ax.tick_params(labelsize=6)
cb2.ax.tick_params(labelsize=6)
cb3.ax.tick_params(labelsize=6)