在记号之间放置标签

2024-10-01 11:20:04 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在plotticks之间放置matlib ticks

例如:在绘制股价随时间变化的图时,我希望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

Tags: 绘制aprjunmarsepmayjanfeb
2条回答

你的意思是这样的: -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)更多选择

编辑:对不起,我没看到你也在问如何在勾号下面加上年份标签。我认为你必须手动操作,看看我链接的例子,看看怎么做。在

这个能行吗?在

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

相关问题 更多 >