如何在GridSpec中将框架居中?

2024-05-23 17:11:30 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在GridSpec分割框架中居中显示图像?我有下面的图片,我想让上面的图片居中。在

Picture to be centered

相关代码(其中的一部分,尤其是单元,来自AMUSE框架):

lim = [-5,5] | units.kpc
bins = [100,100]
xyrange = [[-5,5],[-5,5]]
cmap = cm.jet

hist2d_xy,_,_ = np.histogram2d(particles.x.value_in(units.kpc),particles.y.value_in(units.kpc),bins=bins, range=xyrange)
hist2d_xz,_,_ = np.histogram2d(particles.x.value_in(units.kpc),particles.z.value_in(units.kpc),bins=bins, range=xyrange)

maximum_value = max([hist2d_xy.max(),hist2d_xz.max()])

gs = gridspec.GridSpec(2,1, height_ratios=[3,1])
ax1 = pyplot.subplot(gs[0])


pyplot.imshow(np.flipud(hist2d_xy.T),cmap=cmap,extent = np.array(xyrange).flatten(), interpolation='none',norm=colors.LogNorm(vmin=1,vmax=maximum_value))
cbar = pyplot.colorbar()

ax2 = pyplot.subplot(gs[1])
pyplot.imshow(np.flipud(hist2d_xz.T),cmap=cmap,extent = np.array(xyrange).flatten(), interpolation='none',norm=colors.LogNorm(vmin=1,vmax=maximum_value))
pyplot.ylim([-1,1])
cbar = pyplot.colorbar()
pyplot.tight_layout()
pyplot.savefig(file_location_for_pictures+'test_%.2f.png' %threshold)
pyplot.close()

Tags: invaluenpmaxcmapunitsxyxz
1条回答
网友
1楼 · 发布于 2024-05-23 17:11:30

我换了

gs = gridspec.GridSpec(2,1, height_ratios=[3,1])
ax1 = pyplot.subplot(gs[0])

ax2 = pyplot.subplot(gs[1])

^{pr2}$

(在正确的位置),它现在生成了这张图片(编辑了颜色并添加了一些文本,但想法很清楚):

Centered upper picture

相关问题 更多 >