我想在带有多个子图的图上添加一些注释......在下图中,我想在2右图和左上图下面写一些东西。我怎么能这样做?
我尝试使用:ax3.text(0.1,0.5,' $ \ sigma = $' resV.mean(),size = 12,ha =' center',va =' center')
但是这不起作用,我想指定正确的图的平均值和标准偏差
您可以看到我的代码的一部分:
plt.close()
fig, axes = plt.subplots(nrows=2, ncols=3)
###Figures composante X
plt.tight_layout(pad=0.05, w_pad=0.001, h_pad=2.0)
ax1 = plt.subplot(231) # 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), vmin=U.min(), vmax=U.max())
cb1=plt.colorbar(i1,ax=ax1,ticks=[U.min(),(U.min()+U.max())/2., U.max()],fraction=0.046, pad=0.04,format='%.2f')
cb1.ax.tick_params(labelsize=8)
ax1.set_title("$ \mathrm{Ux_{mes} \/ (pix)}$", y=1.05, fontsize=12)
ax2 = plt.subplot(232) # 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), vmin=UU.min(), vmax=UU.max())
ax2.set_title("$\mathrm{Ux_{cal} \/ (pix)}$", y=1.05, fontsize=12)
ax2.set_xticklabels([])
ax2.set_yticklabels([])
cb2=plt.colorbar(i2,ax=ax2,fraction=0.046, pad=0.04,ticks=[UU.min(),(UU.min()+UU.max())/2.,UU.max()],format='%.2f')
cb2.ax.tick_params(labelsize=8)
ax3 = plt.subplot(233) # 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),vmin=0.,vmax=0.1)
ax3.imshow(scipy.ndimage.filters.gaussian_filter(masquey2, 3),cmap='hot',alpha=0.2,extent=(X.min(),2000,Y.min(),2000))
ax3.set_title("$\mathrm{\mid \/ Ux_{mes} - Ux_{cal}\mid \/ (pix)}$ ", y=1.05, fontsize=12)
cb3=plt.colorbar(i3,ax=ax3,fraction=0.046, pad=0.04,ticks=[0.,0.1],format='%.2f')
ax3.set_xticklabels([])
ax3.set_yticklabels([])
cb3.ax.tick_params(labelsize=8)
plt.gcf().tight_layout()
答案 0 :(得分:2)
这样的事情应该可以正常工作,因为1,5是你真正希望文本出现的位置:
ax3.text(1, 5, 'sigma = {0}'.format(resV.mean()), size=12, ha='center', va='center')
答案 1 :(得分:1)
问:但我不知道如何修改有效位数。
A:预处理要显示的值 round( 1.234567890123456e-2, 5 )
答案 2 :(得分:1)
您可以使用format string syntax
在格式时执行此操作In [23]: 'sigma = {0:.5}'.format(np.pi)
Out[23]: 'sigma = 3.1416'
In [24]: 'sigma = {0:.3}'.format(np.pi)
Out[24]: 'sigma = 3.14'
In [25]: 'sigma = {0:.13}'.format(np.pi)
Out[25]: 'sigma = 3.14159265359'