2014-11-25 2 views
2

동일한 페이지에 7 시리즈를 플롯하기위한 스크립트가 있습니다. 페이지 방향을 세로로 설정하고 싶습니다. 당신이 볼 수 있듯이, 나는 시도했다 :Matplotlib | 방향을 세로로 변경하십시오.

f.savefig(sta+'.pdf', orientation='portrait', format='pdf') 

그러나 아무 일도 일어나지 않는다!

의견이 있으십니까? 사전에

f, (ax1, ax2, ax3, ax4, ax5, ax6, ax7) = plt.subplots(7, sharex=True, sharey=False) 
    plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=0.5) 
    ax1.plot(xtr[:num.size(xt),i], color='black') 
    ax2.plot(ytr[:num.size(yt),i], color='black') 
    ax3.plot(ztr[:num.size(zt),i], color='black') 
    ax4.plot(obs_dataV[:,i], color='g') 
    ax5.plot(obs_dataH[:,i], color='r') 
    ax6.plot(obs_dataP, color='g') 
    ax7.plot(obs_dataS, color='r') 
    ax1.set_title(sta+' Raw data', loc='left', fontsize='10') 
    ax4.set_title('Vertical and Horizontal traces', loc='left', fontsize='10') 
    ax6.set_title('Characteristic functions', loc='left', fontsize='10') 
    ax1.legend('X',loc='center right', fontsize='12') 
    ax2.legend('Y',loc='upper right', fontsize='12') 
    ax3.legend('Z',loc='upper right', fontsize='12') 
    ax4.legend('P',loc='upper right', fontsize='12') 
    ax5.legend('S',loc='upper right', fontsize='12') 
    ax6.legend('P',loc='upper right', fontsize='12') 
    ax7.legend('S',loc='upper right', fontsize='12') 
    f.savefig(sta+'.pdf', orientation='portrait', format='pdf') 
    plt.show() 

덕분에

+0

'orientation = 'portrait''이 (가) h가 아닙니다. 이 경우에는 많은 의미가 있습니다. pdf에있는 페이지의 크기는 그림의 크기로 정의됩니다. (포스트 스크립트 백엔드의 경우 실제로는 약간 다릅니다. kwarg가 의미하는 바입니다.) 그림의 크기를 변경하고 싶습니까? –

+0

그림에서 세로로 플롯을 쌓으려고합니까? 또는 가로로 7 개의 좁은 플롯이되도록 플롯의 가로 세로 비율을 설정 하시겠습니까? – mauve

+0

감사합니다. Joe! 나는 모든 백엔드에서 kwargs가 지원되지 않는다는 것을 몰랐습니다. PS 형식으로 변경했으며 plt.subplots()에서 숫자 크기를 변경했습니다. – CatarinaCM

답변

3

:-) 난 당신이 아니라 페이지 레이아웃 할 필요 무엇보다, 그림의 크기를 변경하고자하는 것 같아요. orientation kwarg ~ savefig은 실제로 PS 및 EPS 백엔드에만 적용됩니다. PDF의 경우 페이지 크기는 그림 크기와 동일하게 정의되므로 아무 효과가 없습니다. 사용

import matplotlib.pyplot as plt 
fig, ax = plt.subplots(nrows=7, sharex=True, sharey=False) 
fig.subplots_adjust(hspace=0.5) 
plt.show() 

enter image description here

이 그림의 크기를 변경하려면 figsize kwarg :

import matplotlib.pyplot as plt 
fig, ax = plt.subplots(nrows=7, figsize=(8, 11), sharex=True, sharey=False) 
fig.subplots_adjust(hspace=0.5) 
plt.show() 

enter image description here을 현재의 결과가 어떻게 표시되는지 간단한 예로서

+2

또는 : fig, axis_array = plt.subplots (7,1, 그림 크기 = (pic_width/7, pic_width), subplot_kw = { 'aspect': 원하는대로)}) – mauve

관련 문제