0
私は、正方形である必要はありimshow
のx軸とクラシックのプロットを共有しようとしています:合わせサブプロット
- 関数imshowは、カラーバーと
- 平方なければならないの
- プロットの蛇腹は同じ軸を共有しなければなりません(少なくとも、imshowと一直線に並ぶように見えます)。
私は2日を過ごしましたが、今は狂っています。誰かがそれらを整列する方法を知っていましたか?
画像を生成するために使用されるコードはベローズです。私は最も簡単な方法は、直接画像下の2番目の軸を持っていることを想像
def myplot(Nbin=20):
X = np.random.rand(1000)
Y = np.random.rand(1000)
h2, yh2, xh2 = np.histogram2d(Y, X, bins=[Nbin,Nbin])
h1, xh1 = np.histogram(X, bins=Nbin)
######################################
######################################
fig = plt.figure()
gs = gridspec.GridSpec(3, 2)
######################################
######################################
ax1 = plt.subplot(gs[:-1,:])
im = plt.imshow(h2, interpolation='nearest', origin='lower',
extent=[xh2[0],xh2[-1],yh2[0],yh2[-1]])
cb = plt.colorbar(im, ax=ax1)
plt.xlim(xh1[0], xh1[-1])
plt.ylim(xh1[0], xh1[-1])
ax1.tick_params(axis='x', which='both', bottom='on', top='on', labelbottom='off')
######################################
######################################
ax2 = plt.subplot(gs[-1,:])
plt.plot(xh1[:-1] + np.diff(xh1)/2., h1)
plt.xlim(xh1[0], xh1[-1])
cm = plt.cm.Blues
cb2 = plt.colorbar(ax=ax2)
ax2.tick_params(axis='x', which='both', bottom='on', top='on', labelbottom='on')
######################################
######################################
fig.tight_layout()
fig.subplots_adjust(hspace=0.05)
cb2.ax.set_visible(False)