2013-11-22 15 views
3

다음과 같이 차트를 작성해야합니다. 이미지와 같이 x 축에 날짜를 표시해야합니다. matplotlib x 레이블 배치

enter image description here

는하지만 난 단지 다음과 같이 차트를 생성 할 수 있었다. enter image description here

나는 수직으로 회전 또는 표시 라벨을 추가 할 수 있습니다 알고이 차트

fig, ax = plt.subplots()    
ax.plot(numpyTradeData.date, numpyTradeData.adj_close) 

#Add Text in Grap 
ax.text(0.5,0.1, 'Class Period\n %s - %s'%(clsStartPeriod.strftime('%B %d, 
%Y'),clsEndPeriod.strftime('%B %d, %Y')), 
horizontalalignment='center', 
fontsize=9, color='red', 
transform=ax.transAxes) 

#Fill An Area in Graph 
ax.fill_between(numpyTradeData.date[classStartPeriodIndex:classEndPeriodIndex], 0, numpyTradeData.adj_close[classStartPeriodIndex:classEndPeriodIndex], facecolor='0.9', alpha='0.5') 

ax.xaxis.set_major_locator(LinearLocator(numticks=5)) 
ax.xaxis.set_major_formatter(dateStrFormatter) 
ax.set_xlim(minDate,maxDate) 
ax.set_ylabel('Share Price') 

formatter = FuncFormatter(self.addDollarSymbol) 
ax.yaxis.set_major_formatter(formatter) 
fig.autofmt_xdate() 

을 생성하기 위해 사용하는 코드를 참조하십시오. 그러나 첫 번째 이미지에서와 같이 레이블을 표시하는 방법을 알아낼 수 없었습니다.

답변

2

set_positionget_position 눈금 개체 방법을 사용할 수 있습니다. 작은 예가 될 것이다 :

import matplotlib.pyplot as plt 
f,a = plt.subplots(1,1) 
a.plot([1,2]) 
ticks = a.xaxis.get_ticklabels() 
for tick in ticks[::2]: 
    tpos = tick.get_position() 
    tick.set_position((tpos[0],tpos[1]-0.05)) 

이것은 0.05 시프트 화면 크기로되어
enter image description here
주를 생성한다.

+0

고마워요 ... – Nick