2014-07-14 3 views
1

플롯 창이 닫힌 후 사용자 선택에 따라 플롯 제목을 변경하고 싶습니다.플롯 윈도우가 파이썬에서 닫힌 후 플롯 제목을 설정하는 방법

ax = pd.rolling_mean(dataToPlot_plot[startTime:endTime][['plotValue']],mar).plot(linestyle='-', linewidth=3, markersize=9, color='#FECB00') 
    ax.legend().set_visible(False) 
    titObj = plt.title('Data Plot - '+"\n", fontsize=13)#plot title 
    plt.show()#showing the plot 

    fig = ax.get_figure() 
    fig.set_size_inches(12, 6) 
    fig.savefig(savePlot) 

은 지금인가,

ax = pd.rolling_mean(dataToPlot_plot[startTime:endTime][['plotValue']],mar).plot(linestyle='-', linewidth=3, markersize=9, color='#FECB00') 
    ax.legend().set_visible(False) 
    titObj = plt.title('Data Plot - '+"\n", fontsize=13)#plot title 
    plt.show()#showing the plot 

    curVal = ax.get_xlim() 
    stdate = int(curVal[0]) 
    endate = int(curVal[1]) 
    difdate = endate - stdate 

    fig = ax.get_figure() 
    if stdate > 0 and endate > 0: 
     if difdate > 365: 
      newplotTitle = 'Data Plot - Since from start' 
     elif difdate > 28 and difdate < 365: 
      newplotTitle = 'Data Plot - Past Month' 
     elif difdate < 28: 
      newplotTitle = 'Data Plot - Past Days' 

     plt.title(newplotTitle+"\n", fontsize=13)#plot title 

    fig.set_size_inches(12, 6) 
    fig.savefig(savePlot) 

새로운 변화

이전 제목으로 개정되지 ... 동적으로 플롯 제목을 변경 플롯의 사용자 선택에 따라와 저장이 모든 필요 이 문제를 해결하는 다른 방법 ... 미리 감사드립니다 ...

답변

1

무슨 일이 발생하는지는 plt 인터페이스가 항상 "현재"그림/축/등을 참조한다는 것입니다.

그림을 닫은 후에는 "현재"축이 비어있는 새로운 플롯입니다. 이것과 다른 여러 가지 이유로

, 그것은 (생성하고 쉽게 수치를 표시 다루는 만든다 plt.figure, plt.subplots, plt.show 같은 기능의 소수 등 제외) 축 방법에 충실하는 것이 가장 좋습니다.

축 또는 그림 개체의 방법을 사용하면 축/그림이 수정되는 관계가 훨씬 명확 해집니다. 그렇지 않으면 "현재"축이 무엇인지 알 필요가 있습니다. 귀하의 경우에는


, 오히려 plt.title('blah')하는 것보다, ax.set(title='blah') (또는 ax.set_title)를 대신 사용합니다.

+0

감사합니다. @Joe Kington, 큰 도움이되었습니다 ... "fig.suptitle (newplotTitle +"\ n ", fontsize = 13) #plot title"이 작동했습니다. 시간과 도움에 감사드립니다. –

관련 문제