Repository navigation
Closed
Labels
Milestone
Description
When using plot_date in the agg backend I get the following error: ValueError: ordinal must be >= 1. The problem does arise in matplotlib 1.5.1 (winpython 2.7.10.3), but not in 1.4.3 (winpython 2.7.10.2).
import matplotlib as mpl
import matplotlib.pyplot as plt
import datetime
plt.switch_backend('agg')
#plt.switch_backend('qt4agg')
x = [datetime.datetime(2013,12,i) for i in range(1, 11)]
y = range(len(x))
plt.plot_date(x,y)
Stack trace:
File "D:/Python/untitled1.py", line 19, in <module>
plt.plot_date(x,y)
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\pyplot.py", line 3173, in plot_date
data=data, **kwargs)
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\__init__.py", line 1812, in inner
return func(ax, *args, **kwargs)
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\axes\_axes.py", line 1494, in plot_date
ret = self.plot(x, y, fmt, **kwargs)
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\__init__.py", line 1812, in inner
return func(ax, *args, **kwargs)
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\axes\_axes.py", line 1424, in plot
for line in self._get_lines(*args, **kwargs):
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\axes\_base.py", line 386, in _grab_next_args
for seg in self._plot_args(remaining, kwargs):
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\axes\_base.py", line 364, in _plot_args
x, y = self._xy_from_xy(x, y)
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\axes\_base.py", line 197, in _xy_from_xy
bx = self.axes.xaxis.update_units(x)
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\axis.py", line 1394, in update_units
self._update_axisinfo()
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\axis.py", line 1412, in _update_axisinfo
self.set_major_locator(info.majloc)
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\axis.py", line 1513, in set_major_locator
self.stale = True
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\artist.py", line 267, in stale
self.stale_callback(self, val)
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\artist.py", line 74, in _stale_axes_callback
self.axes.stale = val
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\artist.py", line 267, in stale
self.stale_callback(self, val)
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\figure.py", line 56, in _stale_figure_callback
self.figure.stale = val
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\artist.py", line 267, in stale
self.stale_callback(self, val)
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\pyplot.py", line 568, in _auto_draw_if_interactive
fig.canvas.draw_idle()
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\backend_bases.py", line 2026, in draw_idle
self.draw(*args, **kwargs)
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\backends\backend_agg.py", line 474, in draw
self.figure.draw(self.renderer)
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\artist.py", line 61, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\figure.py", line 1159, in draw
func(*args)
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\artist.py", line 61, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\axes\_base.py", line 2324, in draw
a.draw(renderer)
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\artist.py", line 61, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\axis.py", line 1106, in draw
ticks_to_draw = self._update_ticks(renderer)
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\axis.py", line 949, in _update_ticks
tick_tups = [t for t in self.iter_ticks()]
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\axis.py", line 892, in iter_ticks
majorLocs = self.major.locator()
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\dates.py", line 1006, in __call__
self.refresh()
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\dates.py", line 1026, in refresh
dmin, dmax = self.viewlim_to_dt()
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\dates.py", line 770, in viewlim_to_dt
return num2date(vmin, self.tz), num2date(vmax, self.tz)
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\dates.py", line 419, in num2date
return _from_ordinalf(x, tz)
File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\matplotlib\dates.py", line 271, in _from_ordinalf
dt = datetime.datetime.fromordinal(ix).replace(tzinfo=UTC)
ValueError: ordinal must be >= 1
Reacted by Dr Yann Golanski
Activity
jusdino commentedon Nov 2, 2016
I just encountered a very similar error with:
When I generate a simple trend chart from a dictionary object with
datetime.datetimefor keys and floats for values, it works fine so long as I'm using the default backend, which I think is TkAgg. As soon as I add a line,matplotlib.use('agg')it throws errors. Sample code and stack trace to below:Code: This runs fine without the 'agg' backend line
Stack Trace:
tacaswell commentedon Nov 2, 2016
works as expected on '2.0.0b3.post29+gbe37777'
@jfursathimn Can you give example data?
jusdino commentedon Nov 2, 2016
Sure, here's a more specific example that again works fine without
matplotlib.use('agg'):Stack Trace:
jusdino commentedon Nov 3, 2016
Some extra info for you:
I ran my most recently posted code (
plt.show()replaced withplt.savefig('/tmp/test.png')) on a Debian system with all modules installed from the official repositories:It ran fine with the
aggbackend. Maybe this is specific to the Windows versions? I installed my Windows version of Python 3.5 from python.org but installed all of thescipyextensions as wpl packages from http://www.lfd.uci.edu/~gohlke/pythonlibs/.QuLogic commentedon Nov 3, 2016
Maybe you can run it in pdb and then print out
ixat the time of the exception? I don't really understand why it would be less than 1, but maybe the actual value could be a clue for what's going wrong.tacaswell commentedon Nov 3, 2016
In the worst developer response ever 'works on my machine' 😞 (linux, anaconda py35, source installed from v1.5.3 tag)
I wonder if this is some how windows specific?
attn @Kojoley
jusdino commentedon Nov 4, 2016
@QuLogic
I'll do that, but I'm no pro at python. You'll have to give me exact instructions for how to use pdb etc.
QuLogic commentedon Nov 4, 2016
It looks like you're running PyDev? You can configure it to break on exceptions, run in the debugger and then inspect the variables there.
Or, from the command-line
python -m pdb Example.py; when it crashes, it should stop. Typeprint ixand thenquitand then tell us what value it says forix. You can also useup/downto navigate the stack frames and maybe print out other interesting variables if you want to investigate further.jusdino commentedon Nov 4, 2016
Thanks for the links. I ran the script in the debugger and... it completed with no errors! I ran it again, unchanged, in the PyDev Console and it produced an exception with a stack trace like above. Out of curiosity then, I ran it again from command-line (no pdb option) and it completed with no errors. I don't get it. Is this a PyDev problem?? They're all using the same python executable.
QuLogic commentedon Nov 4, 2016
print(sys.executable)andprint(matplotlib.__file__)and make sure they're all using the same files.jusdino commentedon Nov 4, 2016
From PyDev console:
From PyDev Debugger:
From command-line:
Looks the same to me.
phobson commentedon Nov 4, 2016
I'll try to check this on my windows machine at work tomorrow.
tacaswell commentedon Nov 4, 2016
This smells like a race condition with the auto-redraw with 'stale' and 'Agg'.
If you run this as
python sc2.pyin fails, run it asipython sc2.pyand it succeeds. I bet in both of the OP casesmpl.rcParams['interactive'] == Truevia .maplotlibrc files.1 remaining item
jonathanng commentedon Jul 16, 2017
I find that this is a fix:
matplotlib.pyplot.ion()kierun commentedon Nov 7, 2017
I think I am running into this issue as well. I am plotting a graph of the last
sizeseconds of some value embedded in a wx GUI. I have a ring buffer of dates and some value (read from a sensor but that does not matter) which is set up like so:Setting the formatting via:
Causes a
ValueError: ordinal must be >= 1when I try to draw the canvas (akaFigureCanvas(self, -1, self.figure)). The tail end of the trace isWhere
x = -0.059999999999999998which is an odd value.I am running Python 3.6.3 on CentOS 7.
Do you need anything else from me?
kierun commentedon Nov 7, 2017
The exact same exception is raised when I call
self.axes.xaxis_date()…dom96 commentedon Nov 16, 2017
This seems related to #9211
I'm getting the same problem and all I'm trying to do is use axvline to plot a vertical line on my chart. I tried passing in a numpy datetime64, a python datetime and whatever pandas.to_datetime returns. All give the same error :\Turns out my issue was just the fact that my index's type was a string. A nicer error message would be nice though!
dstansby commentedon Nov 16, 2017
This bisects back to one of 6 commits in this PR: #4738
aa810b6
0af89d7
770b8d5
14b5a36
69b1b36
252d7a7
kierun commentedon Dec 13, 2017
Updated to version 2.1.1 and things are a little better. I still get the exception when I am creating the plot but as soon as I update them, they render fine.
and
jklymak commentedon Mar 24, 2018
I think this is closed by #10084