题
当我绘制每月采样与酒吧数据,它们的宽度是非常薄的。如果设置了X轴轻微定位器DayLocator(),I可以看到条宽度调整为1天,但我想他们填写了整整一个月。
我试图设置次刻度定位器MonthLocator()没有效果。
<强> [编辑] 强>
也许一个例子将更加明确,这里是我的意思的ipython -pylab
例如:
x = [datetime.datetime(2008, 1, 1, 0, 0),
datetime.datetime(2008, 2, 1, 0, 0),
datetime.datetime(2008, 3, 1, 0, 0),
datetime.datetime(2008, 4, 1, 0, 0),
datetime.datetime(2008, 5, 1, 0, 0),
datetime.datetime(2008, 6, 1, 0, 0),
datetime.datetime(2008, 7, 1, 0, 0),
datetime.datetime(2008, 8, 1, 0, 0),
datetime.datetime(2008, 9, 1, 0, 0),
datetime.datetime(2008, 10, 1, 0, 0),
datetime.datetime(2008, 11, 1, 0, 0),
datetime.datetime(2008, 12, 1, 0, 0)]
y = cos(numpy.arange(12) * 2)
bar(x, y)
这给出了12 2个像素宽条,我想他们得更宽,并从一个月延伸至一个月。
解决方案
只要使用width
关键字参数:
bar(x, y, width=30)
或者,由于不同的月份有天数不同,使其看起来不错,你可以使用一个序列:
bar(x, y, width=[(x[j+1]-x[j]).days for j in range(len(x)-1)] + [30])
不隶属于 StackOverflow