[英]place labels between ticks
在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
這會訣竅嗎?
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')
你的意思是這樣的: - http://matplotlib.sourceforge.net/examples/pylab_examples/barchart_demo.html ??
你必須使用xticks和ha(或'horizontalalignment')參數:
>>> 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)以獲取更多選項
編輯:抱歉,我沒有看到你也在詢問如何將年份標簽放在下方。 我認為你必須手動完成它,看看我已經鏈接的示例,看看如何做到這一點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.