2013-07-28 2 views
0

3x2 행 - 열의 6 개 이미지로 된 A4 용지에 몇 가지 인덱스 데이터를 플로팅합니다. 기본 코드가 작동하고 있으며이 데이터 프레임 데이터를 다음 6 개의 플롯에 표시합니다.matplotlib의 정확한 서브 구조 크기 조정

http://imgur.com/frNjth3

def plot_idx(df,image,key): 
    # reset the default parameters 
    plt.rcParams['font.size'] = 8. 
    plt.rcParams['figure.figsize'] = (8.267, 11.692) #aA paper 
    fig = plt.figure() 
    #plot all the 6 figures and save the 3x2 image as png 

    ax1 = fig.add_subplot(321) # first row first image 
    #compute all time 
    alltime = df['Close'].count() 
    x,y,x_min, y_min, x_max, y_max = min_max(df,alltime) 
    ax1.plot(x, y,'r') 
    ax1.plot(x_min,y_min,'o') 
    ax1.plot(x_max,y_max,'o') 
    ax1.set_xlabel('year') 
    ax1.set_ylabel('Index Close') 
    ax1.set_title(plot_title[-1]) 
    ax1.fill_between(x,y,facecolor='red') 
    ax1.annotate(y_min, xy=(x_min,y_min), xytext=(x_min,y_min +250)) 
    ax1.annotate(y_max, xy=(x_max,y_max), xytext=(x_max,y_max +250)) 

    ax2 = fig.add_subplot(322) # first row second image 
    # compute ytd 
    ytd = df.ix[baseline_year:]['Close'].count() 
    x,y,x_min, y_min, x_max, y_max = min_max(df,ytd) 
    ax2.plot(x, y,'r') 
    .... 
    # repeat 4 more times for other figs 

    fig.suptitle(key, fontsize=10) 
    plt.tight_layout() 
    plt.savefig(image) 

은 어떻게 제목 상단에 공간이 조금로 A4/6 동일한 크기 플롯으로 줄거리를받을 수 있나요? 8.267/2 x 11.69/3 크기에서와 같이? tight_layout은 도움이되지만 크기와 게재 위치를보다 효과적으로 제어하고 싶습니다. 당신이 더 많은 제어를 원하는 경우

+0

내 대답이 문제를 해결 했습니까? – tacaswell

답변

0

, 당신은 아래쪽이 당신이 진드기 확인해야로서, 유지/쓰기 않습니다 정말 귀찮을과 라벨이 오버랩하지 않는 축 fig.add_axesdoc

fig = plt.figure() 
ax1 = fig.add_axes([.1, .1, .4, .4,]) 
ax2 = fig.add_axes([.1, .5, .4, .4,]) 
# ... and so one for as many figures as you want 
# or wrap it all up in a loop 

사용할 수 있습니다 서로 서로 함께.

GridSpec 또한 스패닝 열 등을보다 잘 제어 할 수 있습니다.

+0

subplot의 문맥에서 rect의 값은 무엇을 의미합니까? 나는 l, b, w, h 부분을 볼 수있다. 그러나 왼쪽은 무엇을 의미 하느냐, 바닥은 여기에서 의미한다? – Sivaram

+0

'왼쪽'과 '하단'은 그림 분수 단위로 축의 왼쪽 하단 모서리 위치입니다. – tacaswell

관련 문제