在我的天体物理学实习项目中,我正在创建一个信号过噪声图,我对我的子图有一个小问题,因为为了得到每个热图一个色条,我通过热图得到了3个色条,如下所示:
这是我的剧本(希望它能被理解):
# VERIFICATION DE LA CARTE S/N
# convolution_X and convolution_mask_X are arrays
fig10 = plt.subplot(1,3,1)
step1 = convolution_locale - convolution_mask_locale
fig_step1 = plt.imshow(step1, interpolation='nearest')
plt.colorbar()
plt.xlabel("X (arcmin)")
plt.ylabel("Y (arcmin)")
fig10 = plt.subplot(1,3,2)
step2 = convolution_grande - convolution_mask_grande
fig_step2 = plt.imshow(step2, interpolation='nearest')
plt.colorbar()
plt.xlabel("X (arcmin)")
plt.ylabel("Y (arcmin)")
fig10 = plt.subplot(1,3,3)
S_N_map = step1 - step2
fig_S_N_map = plt.imshow(S_N_map, interpolation='nearest')
plt.colorbar()
plt.xlabel("X (arcmin)")
plt.ylabel("Y (arcmin)")
fig10 = plt.savefig(outname10)
你需要更多关于阵列的信息吗?在
如果你有主意,谢谢你!在
出于某些原因,图10积累了多余的颜色条;这将产生您想要的结果(我认为):
请注意,我修改了绘制的数组的构造(在代码中指出)
你的代码变得混乱,因为你没有告诉它哪个颜色条属于哪个子批次。在
在这里,使用matplotlib面向对象的方法将非常有帮助。如果您创建图形和子图实例(例如使用
plt.subplots()
),那么您可以在每个实例上调用绘图(例如ax1.imshow
)和标记(例如ax1.set_xlabel
)方法,而不需要使用plt
。然后,当您创建颜色条(fig10.colorbar()
)时,您可以使用ax
kwarg来告诉它在哪个子批创建colorbar。在您还将可映射对象(例如
fig_step1
)提供给对fig10.colorbar
的调用,以确保使用正确的数组来创建colorbar比例。在相关问题 更多 >
编程相关推荐