2017-04-11 12 views
0

私は以下のイメージのようなプロットを作成したいと思います。この図には2つのユニークなプロットがあります。 img1plt.imshow()を使用して生成され、img2plt.plot()を使用して生成されました。私はプロットの各々を生成するために使用されるコードはimg1に使用される行列は64x64あるMatplotlibサブプロット:imshow + plot

plt.clf() 
plt.imshow(my_matrix) 
plt.savefig("mymatrix.png") 

plt.clf() 
plt.plot(x,y,'o-') 
plt.savefig("myplot.png") 

下方に設けられています。 img2のx軸(x=range(64))と同じ範囲です。理想的には、img2のx軸はimg1の軸に揃えられます。

最後の画像は海底のjointplot()を連想させるが、下の画像の限界サブプロット(img2)は分布図を示さないことに注意することが重要である。

Ideal output with annotation

答えて

1

あなたは、中央imshowプロットの両方の方向に沿って共有軸を作成するためにmpl_toolkits.axes_grid1make_axes_locatable機能を使用することができます。ここで

は一例です:

import matplotlib.pyplot as plt 
from mpl_toolkits.axes_grid1 import make_axes_locatable 
import numpy as np; np.random.seed(0) 

Z = np.random.poisson(lam=6, size=(64,64)) 
x = np.mean(Z, axis=0) 
y = np.mean(Z, axis=1) 

fig, ax = plt.subplots() 
ax.imshow(Z) 

# create new axes on the right and on the top of the current axes. 
divider = make_axes_locatable(ax) 
axtop = divider.append_axes("top", size=1.2, pad=0.3, sharex=ax) 
axright = divider.append_axes("right", size=1.2, pad=0.4, sharey=ax) 
#plot to the new axes 
axtop.plot(np.arange(len(x)), x, marker="o", ms=1, mfc="k", mec="k") 
axright.plot(y, np.arange(len(y)), marker="o", ms=1, mfc="k", mec="k") 
#adjust margins 
axright.margins(y=0) 
axtop.margins(x=0) 
plt.tight_layout() 
plt.show() 

enter image description here

+0

すごいです!これは私が必要なものです!ありがとう! – EFL

関連する問題