强制使用科学记数法

时间:2019-06-23 14:47:49

标签: python matplotlib colorbar

在此绘图中,我的色条上的数字有问题。中间的两个面板通过在底部添加1e-7来完成应做的事情,而左侧和右侧的面板则没有。有什么办法可以迫使其他两个人采取这种行为? enter image description here

此代码重现了随机像素的行为。

a = np.random.random((1,4,20,300,300))
X = -557
Y = 80
pixel_scale = 0.058

xb = X - 490*pixel_scale
yb = Y - 483*pixel_scale
xe = X + 490*pixel_scale
ye = Y + 483*pixel_scale

fig, axs = plt.subplots(1, 4, sharex='col', sharey='row',
                        gridspec_kw={'hspace': 0, 'wspace': 0})
(ax1, ax2, ax3, ax4)= axs

im1 = ax1.imshow(np.rot90(a[0,0,11])*1e-5, origin='lower', cmap='gray', extent=[xb,xe,yb,ye])
im2 = ax2.imshow(np.rot90(a[0,1,11])*1e-7, origin='lower', cmap='gray', extent=[xb,xe,yb,ye])
im3 = ax3.imshow(np.rot90(a[0,2,11])*1e-7, origin='lower', cmap='gray', extent=[xb,xe,yb,ye])
im4 = ax4.imshow(np.rot90(a[0,3,11])*1e-5, origin='lower', cmap='gray', extent=[xb,xe,yb,ye])


for ax in axs.flat:
    ax.label_outer()

p1 = axs[0].get_position().get_points().flatten()
p2 = axs[1].get_position().get_points().flatten()
p3 = axs[2].get_position().get_points().flatten()
p4 = axs[3].get_position().get_points().flatten()

ax_cbar1 = fig.add_axes([p1[0], 0.88, p1[2]-p1[0], 0.05])
cb1 = plt.colorbar(im1, cax=ax_cbar1, orientation='horizontal',ticklocation = 'top')
cb1.formatter.set_powerlimits((0, 0))

ax_cbar2 = fig.add_axes([p2[0], 0.88, p2[2]-p2[0], 0.05])
plt.colorbar(im2, cax=ax_cbar2, orientation='horizontal',ticklocation = 'top')

ax_cbar3 = fig.add_axes([p3[0], 0.88, p3[2]-p3[0], 0.05])
plt.colorbar(im3, cax=ax_cbar3, orientation='horizontal',ticklocation = 'top')

ax_cbar4 = fig.add_axes([p4[0], 0.88, p4[2]-p4[0], 0.05])
plt.colorbar(im4, cax=ax_cbar4, orientation='horizontal',ticklocation = 'top')

fig.text(0.5, 0.04, 'X [arcsec]', ha='center')
ax1.set_ylabel('Y [arcsec]')

plt.show()

0 个答案:

没有答案