-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH/BUG: support TimedeltaIndex plotting #8711
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
I don't think that matplotlib already has a converter for But writing a basic converter should not be that difficult I think (and if it also works for |
Timedelta is s. subclass of datetime.timedelta |
I just encountered a MemoryError when attempting to plot a TimedeltaIndex!
|
Working on this. Doesn't look too bad. |
As an update, it's a bit worse than I thought. I think it was @changhiskhan who put in a ton of heuristics for figuring out what to resolution to draw when plotting datetimes. I wasn't sure if we'd need that for timedeltas, and then I got busy with other thing. My branch is here |
As a workaround, the following works with master: plt.plot(s.index,s.values) |
I don't think freq adjustment of different timedeltas is mandatory at initial version. If ok, I'll try. |
Coming here from #10650, and adding a little more info just in case it can help. In my case, the bug manifests in
allocates a gigantic array. To be specific, when doing:
the values of |
@lucas-eyer is the |
I don't know what appropriate would be, but it's Edit: |
I also just ran into this issue on 0.17.1. I'm not very familiar with the code, but it appears the issue is in The issue is that
But downstream in _daily_finder the
Replacing the final line above with
appears to fix the issue. |
@Liam3851 glad you have tracked this down! Any chance you're interested in making a pull request with the fix? :) |
Sure, I just have to figure out how to do it lol. Longtime pandas user but kinda new on this github thingy. I'll head over to the FAQ. |
Great! Give it a try and let us know if you have any questions :). On Wed, Jan 13, 2016 at 11:48 AM, Liam3851 [email protected] wrote:
|
Lots of love from me too @Liam3851! |
Hmm, ok still slightly more complicated. Was testing the fix and the bounds are now right and the graphs themselves look correct but the axis labels don't always work properly (sometimes they disappear)-- probably something related to how the labels are interpreted. I'm busy these next few days but I'll try to get around to making the fix sound. |
Just guessing, but you could be hitting what I ran into. I can't remember how much progress if any I made on that. |
@TomAugspurger Hmm.. I'll try your version to see what it does. From the diff it looks like we're taking slightly different paths. It looks like you were building a TimedeltaConverter that worked parallel to DatetimeConverter and TimeConverter; I've been trying to fix the codepath the timedeltas are currently taking (through DatetimeConverter). But it's entirely possible that getting it to look just right will require going down your path. |
I’d say getting it somewhat functional is good enough for now. Hopefully you don’t have to go down that rabbit hole.
|
Hello. I am using pandas version 0.19.0 and matplotlib version 1.5.3 with python 3 and this issue is still there: If I try to plot a Dataframe where the index is a timedelta I get |
@sam-cohan As you can see, the issue is still open, so it's indeed not yet solved. But any help is certainly welcome! |
Sorry I was looking at the wrong "Closed" :) |
Really wish this was fixed. I'm using datetime as a work around but stringing along 1970-01-01 to do time deltas is not fun. |
@TomAugspurger does your branch with a first attempt still exist? (the link above is not working anymore) |
So the issue here is that we are trying to use the Int64Index as a base class for TimedeltaIndex but we are trying to use the plotting routines for the PeriodIndex which relies on DatetimeIndex (matplotlib.date) underneath. Matplotlib.date scales the view interval to the selected frequency. Int64Index does not, so this explains the issues above. Options:
|
@jgoppert you should take a look at |
@jorisvandenbossche I did consider that approach, but I think having a separate matplotlib plotting function is cleaner and will require less maintenance. We also won't have to worry about ever seeing jan 1970 on the time delta plot like we do on the period index based plots now. It seems pretty robust and I have added nano-second level precision labels. |
Seems like I deleted that branch when I was cleaning up my fork. I didn't get far beyond the |
@TomAugspurger can you take a look at my PR. Totally different approach but seems to work for me. |
Does this mean the fix for this will be in next release? If so, what is the timeline for that? Thanks in advance. |
@sam-cohan yes it will be in 0.20.0 I think we are still about 1 month away from an rc. |
Author: James Goppert <[email protected]> Author: James Goppert <[email protected]> Closes pandas-dev#8711 Closes pandas-dev#15067 from jgoppert/tdi_plot_fix and squashes the following commits: 945ec14 [James Goppert] Merge branch 'master' into tdi_plot_fix 7db61ec [James Goppert] Create TimeSeries_TimedeltaFormatter. 232efe6 [James Goppert] Fix comment format and exception type for tdi plotting. 4eff697 [James Goppert] Add more time delta series plotting tests. f5f32bc [James Goppert] Link time delta index docs to better matplotlib docs. d588c2c [James Goppert] Fixes test for tdi w/o autofmt_xdate. b6e6a81 [James Goppert] Disables autofmt_xdate testing. c7851e3 [James Goppert] Adjusts tdi test draw calls to try to fix CI issue. 7d28842 [James Goppert] Switch to draw_idle to try to fix bug on xticks update. 3abc310 [James Goppert] Try plt.draw() instead of canvas.draw() to fix issue on osx 3.5. 91954bd [James Goppert] Finished unit test for timedelta plotting. 41ebc85 [James Goppert] Fixes for review comments from pandas-dev#15067. f021cbd [James Goppert] Support nano-second level precision x-axis labels. 5ec65fa [James Goppert] Plot fix for tdi and added more comments. b967d24 [James Goppert] flake8 fixes for tdi plotting. efe5636 [James Goppert] Adds custom plot formatting for TimedeltaIndex.
I am having a similar issue today using version 2.1.2. See this stackoverflow post where I include a reproducible example: This bug is quite hard to track down and dangerous because it may or may not occur depending on particular values in the data to be plotted. Is this the same issue or should I raise a new one? |
This raises
This will show the timedeltas with a formatted (albeit string index)
wonder if we can just register a converter somehow? like #8614
The text was updated successfully, but these errors were encountered: