python - Floating Bar Chart -
i'm trying make plot x-axis time , y-axis bar chart have bars covering time period this:
______________ |_____________| _____________________ |___________________| -----------------------------------------------------> time
i have 2 lists of datetime values start , end of these times i'd have covered. far have
x = np.array([dt.datetime(2010, 1, 8, i,0) in range(24)])
to cover 24-hour period. question how set , plot y-values this?
you use plt.barh
:
import datetime dt import numpy np import matplotlib.pyplot plt import matplotlib.dates mdates start = [dt.datetime(2000,1,1)+dt.timedelta(days=i) in (2,0,3)] end = [s+dt.timedelta(days=i) s,i in zip(start, [15,7,10])] start = mdates.date2num(start) end = mdates.date2num(end) yval = [1,2,3] width = end-start fig, ax = plt.subplots() ax.barh(bottom=yval, width=width, left=start, height=0.3) xfmt = mdates.dateformatter('%y-%m-%d') ax.xaxis.set_major_formatter(xfmt) # autorotate dates fig.autofmt_xdate() plt.show()
yields
Comments
Post a Comment