2017-04-11 3 views
0

아래 그림과 같은 그림을 만들고 싶습니다. 그림에는 두 개의 고유 한 플롯이 있습니다. img1plt.imshow()을 사용하여 생성되었고, img2plt.plot()을 사용하여 생성되었습니다. I가 플롯들 각각을 생성하기 위해 사용되는 코드Matplotlib subplot : imshow + plot

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

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

img1 이하에서 사용되는 행렬을 제공 64x64이다. img2의 x 축 (x=range(64))과 동일한 범위입니다. 이상적으로 두 개의 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

관련 문제