I'd like to create a broken vertical bar graph in matplotlib.
To give a better idea of the result I'm after, I put an example together with Balsamiq:
I've had a look at the matpltolib docs and examples but I can't seem to find the appropriate chart type to use. The only thing that looks remotely similar is the boxplot but this isn't what I need.
- I'd rather not have to draw the graph manually with graphics primitive.
- I can massage the data into shape as needed.
PS: If you know of a good library that does this in another language (javascript, for example), I'd be grateful for the pointer too.
It sounds like you have a few series of start datetimes and stop datetimes.
In that case, just use
bar
to plot things, and tell matplotlib that the axes are dates.To get the times, you can exploit the fact that matplotlib's internal date format is a float where each integer corresponds to 0:00 of that day. Therefore, to get the times, we can just do
times = dates % 1
.As an example (90% of this is generating and manipulating dates. The plotting is just a single call to
bar
.):On a side note, for events that start on one day and end on the next, this will extend the y-axis into the next day. You can handle it in other ways if you prefer, but I think this is the simplest option.