Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Cannot use a timedelta Rectangle width with a datetime axis #4916
I would like to draw a rectangle to represent the weekend on a plot whose x-axis is time. In an IPython Notebook:
The big problem is that the above code dies with an exception.
The other problem is that my backup plan, of replacing the
Why is a
Thanks for any help you can provide!
@brandon-rhodes I faced the same problem as you, to annotate a graph using a rectangle.
My workaround is to define a function, it can automatically use timestamp as x axis.
# draw a rectangle def annote_rect(ax, x, y, w, h): t = [x, x+w, x+w, x, x] d = [y, y, y+h, y+h, y] ax.plot(t, d, 'm--', lw=2)
Another workaround is to subclass
class OrdinalTimedelta(datetime.timedelta): _origin = datetime.date(1, 1, 1) def toordinal(self): return (self._origin + self).toordinal()
I don't really have time, and I haven't tested if I could break it (or read the code to see why matplotlib needed to `toordinal`), but it does work for my usecase. It might be good to have an example though since it makes plotting something like a Gantt plot more elegant.…
On 12/05/2017 17:51, Benjamin Root wrote: Clever! Would you like to make an example show-casing this?