2009-10-25 83 views
7

,我怎麼把蜱蜱之間標籤(不低於蜱)地點標籤之間蜱matplotlib

例如:隨着時間的推移繪製股票價格時,我想x軸次刻度顯示月,這些年來出現連續的x軸主刻度之間(而不僅僅是低於主刻度)

---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|--- 
    jan feb mar apr may jun jul aug sep oct nov dec jan feb mar apr may jun jul aug sep 
         2008           2009 

回答

5

這會做詭計嗎?

enter code here 
x = 'j f m a m j j a s o n d j f m a m j j a s o n d'.split() 
y = abs(randn(24)) 
x[6] = 'j\n2008' # replace "j" (January) with ('j' and the appropriate year 
x[18] = 'j\n2009' 
bar(xrange(len(x)), y, width=0.1) 
bar(xrange(len(x)), y, width=0.1) 
xticks(xrange(len(x)), x, ha='center') 

Barchart with proper labels

+0

圖像不可用(ImageShack的的主頁) – 2018-01-11 13:54:35

+0

@PierreCordier謝謝,固定 – 2018-01-18 02:35:25

1

你的意思是這樣的: - http://matplotlib.sourceforge.net/examples/pylab_examples/barchart_demo.html

必須使用xticks和HA(或 '的Horizo​​ntalAlignment')參數:

>>> x = 'j f m a m j j a s o n d'.split() 
>>> y = abs(randn(12)) 
>>> bar(xrange(len(x)), y, width=0.1) 

>>> xticks(xrange(len(x)), x, ha='center') 

看看幫助(xticks)和幫助(matplotlib.text.Text)以獲得更多選項

編輯:對不起,我沒有看到你也在問如何將年份標籤放在滴答聲下。我認爲你必須手動完成,看看我已經鏈接的例子,看看如何做到這一點。