1
如何將圖像置於GridSpec分隔框中?我已經得到了下面的圖片,我想讓上面的圖片居中。如何在GridSpec中對齊框架?
相關的代碼(它的一部分,尤其是單位,是從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()
做一個3x2的網格,有一個底部跨度所有三個最高的一個只使用中間。 – tacaswell 2015-02-09 14:02:00
http://matplotlib.org/users/gridspec.html – tacaswell 2015-02-09 14:02:42
我使用'subplot2grid()',但上面的圖片太小了。但感謝鏈接,'subplot2grid()'似乎非常方便。 – Mathias711 2015-02-09 14:27:59