-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Cannot use a timedelta Rectangle width with a datetime axis #4916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
As a work around I would try using |
@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() |
Clever! Would you like to make an example show-casing this? |
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?
|
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
timedelta()
with the floating-point value 2.0, destroys the date-ness of thex
axis. It reverts to being a float that does not display as a date.Why is a
timedelta
not a valid increment or offset with which I can express width along a datetime x-axis?Thanks for any help you can provide!
The text was updated successfully, but these errors were encountered: