-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
plot_date() does not work with x values of type pandas.Timestamp (pandas version 0.15.0)? #3727
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
Here is my original script that I made this past January which worked fine back then. So looks like now it doesn't work with newer versions of MATPLOTLIB or newer version of pandas. http://nbviewer.ipython.org/gist/pybokeh/416b6fb2910475ef8e68 |
Would you strip this down to a SSCCE, please? Preferably a script with minimal dependencies, e.g., no pandas. |
I suspect that this is more datetime64 issues. |
OK so my title is misleading, it should say plot_date() doesn't work with x values of type pandas.Timestamp as this simplified example shows: http://nbviewer.ipython.org/gist/pybokeh/92d28fa729bd38be8b92 It is throwing exception: |
That warning is coming out of IPython code, not out of mpl code. Can you reproduce without ipython and without pandas? attn @takluyver @jreback can you point someone for your projects at this? |
I can not re-produce without pandas. The problem appears to be with pandas Timeseries object which is why I changed the title. Whether or not plot_date() should work with pandas.Timeseries, that I can not say. I believe back in January, my original bitcoin chart script did work, but I would have to duplicate the same environment that I had back then to confirm what the exact data that I had passed in. This works fine: d1 = datetime(2001,5,1) dates = [] values = [1,2,3] plt.plot_date(dates, values, 'r') type(dates[0]) returns: |
The change might be because of some fixes to applying units conversion (an On Mon, Oct 27, 2014 at 11:42 AM, pybokeh notifications@github.com wrote:
|
Is it possible that the issue is due to a upgrade of Pandas version? Pandas have changed some of their objects to no longer subclass numpy ndarray which has previously broken plotting of pandas object. See http://matplotlib.org/faq/usage_faq.html?highlight=pandas#types-of-inputs-to-plotting-functions |
|
@tacaswell - the warning comes from IPython, but that's because IPython catches an error in a formatter and turns it into a warning, I believe. |
OK, at work I created an environment with pandas 0.14.1 and my bitcoin chart script works. Uninstalled pandas 0.14.1 and then installed pandas 0.15.0. Now, it does not work. EDIT: Python 3.4.2, So looks like the issue has to do with something that has apparently changed with pandas 0.15.0. |
This is a 'regression' in pandas 0.15 (due to the refactor of Index), see pandas-dev/pandas#8614. Running |
pandas-dev/pandas#8693 should solve this |
Actually, wouldn't it make sense to get this into matplotlib? Supporting On Wed, Nov 5, 2014 at 9:44 AM, Joris Van den Bossche <
|
yes certainly (the issue for this: #1097) The merged PR (pandas-dev/pandas#8693) just solves this specific issue regarding plotting a pandas |
All gist links are broken. Is there another example that we can use to confirm the fix provided? |
This issue can actually just be closed I think. The actual issue reported here is closed by a PR in pandas in version 0.15.1(so only pandas 0.15.0 has this problem), and the larger issue (better datetime support in matplotlib) is covered by #1097 |
I re-ran my old examples and confirmed that with latest version of mpl and pandas, all works ok. Closing this issue. |
It seems like this problem happens in pandas 0.21.0. code to reproduce this error import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import dates
t = np.arange(10)
ts = pd.datetime(2017, 11, 16) + pd.to_timedelta(t, 's')
df = pd.DataFrame(t, index=ts)
fig, ax = plt.subplots()
ax.plot(df)
# format time axis
hfmt = dates.DateFormatter('%m/%d %H:%M')
ax.xaxis.set_major_formatter(hfmt)
fig.autofmt_xdate()
plt.show() The trace Traceback (most recent call last):
File "D:\Anaconda3\lib\site-packages\IPython\core\formatters.py", line 332, in __call__
return printer(obj)
File "D:\Anaconda3\lib\site-packages\IPython\core\pylabtools.py", line 237, in <lambda>
png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
File "D:\Anaconda3\lib\site-packages\IPython\core\pylabtools.py", line 121, in print_figure
fig.canvas.print_figure(bytes_io, **kw)
File "D:\Anaconda3\lib\site-packages\matplotlib\backend_bases.py", line 2208, in print_figure
**kwargs)
File "D:\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 507, in print_png
FigureCanvasAgg.draw(self)
File "D:\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 430, in draw
self.figure.draw(self.renderer)
File "D:\Anaconda3\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "D:\Anaconda3\lib\site-packages\matplotlib\figure.py", line 1295, in draw
renderer, self, artists, self.suppressComposite)
File "D:\Anaconda3\lib\site-packages\matplotlib\image.py", line 138, in _draw_list_compositing_images
a.draw(renderer)
File "D:\Anaconda3\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "D:\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 2399, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "D:\Anaconda3\lib\site-packages\matplotlib\image.py", line 138, in _draw_list_compositing_images
a.draw(renderer)
File "D:\Anaconda3\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "D:\Anaconda3\lib\site-packages\matplotlib\axis.py", line 1133, in draw
ticks_to_draw = self._update_ticks(renderer)
File "D:\Anaconda3\lib\site-packages\matplotlib\axis.py", line 974, in _update_ticks
tick_tups = list(self.iter_ticks())
File "D:\Anaconda3\lib\site-packages\matplotlib\axis.py", line 921, in iter_ticks
for i, val in enumerate(majorLocs)]
File "D:\Anaconda3\lib\site-packages\matplotlib\axis.py", line 921, in <listcomp>
for i, val in enumerate(majorLocs)]
File "D:\Anaconda3\lib\site-packages\matplotlib\dates.py", line 538, in __call__
dt = num2date(x, self.tz)
File "D:\Anaconda3\lib\site-packages\matplotlib\dates.py", line 441, in num2date
return _from_ordinalf(x, tz)
File "D:\Anaconda3\lib\site-packages\matplotlib\dates.py", line 256, in _from_ordinalf
dt = datetime.datetime.fromordinal(ix).replace(tzinfo=UTC)
OverflowError: Python int too large to convert to C long
<matplotlib.figure.Figure at 0xebecc88> |
See #9610 (short story is that pandas no longer automatically registers its unit converters starting from 0.21.0), but we will fix this in upcoming 0.21.1 to at least first give deprecation warning (pandas-dev/pandas#18301) |
Please see my ipython notebook gist:
http://nbviewer.ipython.org/gist/pybokeh/f2aab3aafdc287d02bb8
Basically, if I try to plot_date() using x values of type datetime, I get weird errors. But if I convert the x values to type datetime.date, then it plots ok.
EDIT: the only difference between In[3] and In[4] is I used list comprehension in the plot_date() method in In[4] to convert the x values to type datetime.date.
The text was updated successfully, but these errors were encountered: