Controlling bars width in matplotlib with per-month data

后端 未结 1 1999
有刺的猬
有刺的猬 2021-02-18 23:20

When I plot data sampled per month with bars, their width is very thin. If I set X axis minor locator to DayLocator(), I can see the bars width is adjusted to 1 day, but I would

相关标签:
1条回答
  • 2021-02-19 00:05

    Just use the width keyword argument:

    bar(x, y, width=30)
    

    Or, since different months have different numbers of days, to make it look good you can use a sequence:

    bar(x, y, width=[(x[j+1]-x[j]).days for j in range(len(x)-1)] + [30])
    
    0 讨论(0)
提交回复
热议问题