I know about plot_date()
but is there a bar_date()
out there?
The general method would be to use set_xticks
and set_xticklabels
, but I'd like something that can handle time scales from a few hours out to a few years (this means involving the major and minor ticks to make things readable I think).
Edit: I realized that I am plotting values associated with a specific time interval (that the bar spans). I updated below with the basic solution I used:
import matplotlib.pyplot as plt
import datetime
t=[datetime.datetime(2010, 12, 2, 22, 0),datetime.datetime(2010, 12, 2, 23, 0), datetime.datetime(2010, 12, 10, 0, 0),datetime.datetime(2010, 12, 10, 6, 0)]
y=[4,6,9,3]
interval=1.0/24.0 #1hr intervals, but maplotlib dates have base of 1 day
ax = plt.subplot(111)
ax.bar(t, y, width=interval)
ax.xaxis_date()
plt.show()
question from:
https://stackoverflow.com/questions/5902371/matplotlib-bar-chart-with-dates 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…