Skip to content

Error with plot_date and agg backend: ValueError: ordinal must be >= 1 #6023

Closed

Description

@mvds314

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

Activity

  1. jusdino commented on Nov 2, 2016

    @jusdino

    I just encountered a very similar error with:

    • python 3.5
    • matplotlib 1.5.3
    • in Windows 10

    When I generate a simple trend chart from a dictionary object with datetime.datetime for 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

    import os
    import matplotlib
    matplotlib.use('agg')
    import matplotlib.pyplot as plt
    import matplotlib.dates as mdates
    
    ... define aggData dictionary ...
    
    fig = plt.figure(figsize=(6.5,5))
    ax = fig.add_subplot(111)
    hfmt = mdates.DateFormatter('%x\n%X')
    ax.plot_date([k for k in aggData.keys()], [v for v in aggData.values()], fmt='r-')
    ax.xaxis.set_major_formatter(hfmt)
    plt.xticks(rotation=60)
    plt.subplots_adjust(top=1.0, bottom=0.2)
    plt.show()
    

    Stack Trace:

    Traceback (most recent call last):
    File "<input>", line 1, in <module>
    File "C:\...\DataSet.py", line 260, in demo
        ax.plot_date([k for k in aggData.keys()], [v for v in aggData.values()], fmt='r-')
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\__init__.py", line 1819, in inner
        return func(ax, *args, **kwargs)
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\axes\_axes.py", line 1453, in plot_date
        self.xaxis_date(tz)
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\axes\_base.py", line 3182, in xaxis_date
        self.xaxis.axis_date(tz)
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\axis.py", line 1646, in axis_date
        self.update_units(datetime.datetime(2009, 1, 1, 0, 0, 0, 0, tz))
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\axis.py", line 1396, in update_units
        self._update_axisinfo()
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\axis.py", line 1414, in _update_axisinfo
        self.set_major_locator(info.majloc)
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\axis.py", line 1515, in set_major_locator
        self.stale = True
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\artist.py", line 270, in stale
        self.stale_callback(self, val)
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\artist.py", line 75, in _stale_axes_callback
        self.axes.stale = val
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\artist.py", line 270, in stale
        self.stale_callback(self, val)
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\figure.py", line 56, in _stale_figure_callback
        self.figure.stale = val
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\artist.py", line 270, in stale
        self.stale_callback(self, val)
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\pyplot.py", line 576, in _auto_draw_if_interactive
        fig.canvas.draw_idle()
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\backend_bases.py", line 2026, in draw_idle
        self.draw(*args, **kwargs)
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\backends\backend_agg.py", line 474, in draw
        self.figure.draw(self.renderer)
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\artist.py", line 62, in draw_wrapper
        draw(artist, renderer, *args, **kwargs)
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\figure.py", line 1159, in draw
        func(*args)
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\artist.py", line 62, in draw_wrapper
        draw(artist, renderer, *args, **kwargs)
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\axes\_base.py", line 2319, in draw
        a.draw(renderer)
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\artist.py", line 62, in draw_wrapper
        draw(artist, renderer, *args, **kwargs)
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\axis.py", line 1108, in draw
        ticks_to_draw = self._update_ticks(renderer)
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\axis.py", line 951, in _update_ticks
        tick_tups = [t for t in self.iter_ticks()]
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\axis.py", line 951, in <listcomp>
        tick_tups = [t for t in self.iter_ticks()]
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\axis.py", line 894, in iter_ticks
        majorLocs = self.major.locator()
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\dates.py", line 1007, in __call__
        self.refresh()
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\dates.py", line 1027, in refresh
        dmin, dmax = self.viewlim_to_dt()
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\dates.py", line 771, in viewlim_to_dt
        return num2date(vmin, self.tz), num2date(vmax, self.tz)
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\dates.py", line 419, in num2date
        return _from_ordinalf(x, tz)
    File "C:\Program Files\Python35\lib\site-packages\matplotlib\dates.py", line 271, in _from_ordinalf
        dt = datetime.datetime.fromordinal(ix).replace(tzinfo=UTC)
    ValueError: ordinal must be >= 1
    
  2. added this to the milestone on Nov 2, 2016
  3. tacaswell commented on Nov 2, 2016

    @tacaswell
    Member
    import matplotlib as mpl
    mpl.use('agg')
    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))
    fig, ax = plt.subplots()
    ax.plot_date(x,y)
    fig.savefig('/tmp/test.png')

    test

    works as expected on '2.0.0b3.post29+gbe37777'

    @jfursathimn Can you give example data?

  4. jusdino commented on Nov 2, 2016

    @jusdino

    Sure, here's a more specific example that again works fine without matplotlib.use('agg'):

    import matplotlib
    matplotlib.use('agg')
    import matplotlib.pyplot as plt
    import matplotlib.dates as mdates
    import datetime
    from collections import OrderedDict
    
    aggData = OrderedDict([(datetime.datetime(2016, 10, 17, 0, 0), 0.16289695106620844), (datetime.datetime(2016, 10, 18, 0, 0), 0.23634330902782563)])
    
    print('\nGenerating sample plot...')
    fig = plt.figure(figsize=(6.5,5))
    ax = fig.add_subplot(111)
    hfmt = mdates.DateFormatter('%x\n%X')
    ax.plot_date([k for k in aggData.keys()], [v for v in aggData.values()], fmt='r-')
    ax.xaxis.set_major_formatter(hfmt)
    plt.xticks(rotation=60)
    plt.subplots_adjust(top=1.0, bottom=0.2)
    plt.show()
    

    Stack Trace:

    Traceback (most recent call last):
      File "<input>", line 1, in <module>
      File "C:\Users\jfursathimn\.p2\pool\plugins\org.python.pydev_5.3.0.201610121612\pysrc\_pydev_bundle\pydev_umd.py", line 167, in runfile
        execfile(filename, namespace)
      File "C:\Users\jfursathimn\.p2\pool\plugins\org.python.pydev_5.3.0.201610121612\pysrc\_pydev_imps\_pydev_execfile.py", line 25, in execfile
        exec(compile(contents+"\n", file, 'exec'), glob, loc)
      File "C:\Users\jfursathimn\Documents\eclipse\data_screening\Example.py", line 15, in <module>
        ax.plot_date([k for k in aggData.keys()], [v for v in aggData.values()], fmt='r-')
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\__init__.py", line 1819, in inner
        return func(ax, *args, **kwargs)
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\axes\_axes.py", line 1453, in plot_date
        self.xaxis_date(tz)
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\axes\_base.py", line 3182, in xaxis_date
        self.xaxis.axis_date(tz)
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\axis.py", line 1646, in axis_date
        self.update_units(datetime.datetime(2009, 1, 1, 0, 0, 0, 0, tz))
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\axis.py", line 1396, in update_units
        self._update_axisinfo()
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\axis.py", line 1414, in _update_axisinfo
        self.set_major_locator(info.majloc)
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\axis.py", line 1515, in set_major_locator
        self.stale = True
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\artist.py", line 270, in stale
        self.stale_callback(self, val)
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\artist.py", line 75, in _stale_axes_callback
        self.axes.stale = val
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\artist.py", line 270, in stale
        self.stale_callback(self, val)
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\figure.py", line 56, in _stale_figure_callback
        self.figure.stale = val
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\artist.py", line 270, in stale
        self.stale_callback(self, val)
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\pyplot.py", line 576, in _auto_draw_if_interactive
        fig.canvas.draw_idle()
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\backend_bases.py", line 2026, in draw_idle
        self.draw(*args, **kwargs)
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\backends\backend_agg.py", line 474, in draw
        self.figure.draw(self.renderer)
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\artist.py", line 62, in draw_wrapper
        draw(artist, renderer, *args, **kwargs)
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\figure.py", line 1159, in draw
        func(*args)
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\artist.py", line 62, in draw_wrapper
        draw(artist, renderer, *args, **kwargs)
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\axes\_base.py", line 2319, in draw
        a.draw(renderer)
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\artist.py", line 62, in draw_wrapper
        draw(artist, renderer, *args, **kwargs)
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\axis.py", line 1108, in draw
        ticks_to_draw = self._update_ticks(renderer)
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\axis.py", line 951, in _update_ticks
        tick_tups = [t for t in self.iter_ticks()]
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\axis.py", line 951, in <listcomp>
        tick_tups = [t for t in self.iter_ticks()]
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\axis.py", line 894, in iter_ticks
        majorLocs = self.major.locator()
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\dates.py", line 1007, in __call__
        self.refresh()
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\dates.py", line 1027, in refresh
        dmin, dmax = self.viewlim_to_dt()
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\dates.py", line 771, in viewlim_to_dt
        return num2date(vmin, self.tz), num2date(vmax, self.tz)
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\dates.py", line 419, in num2date
        return _from_ordinalf(x, tz)
      File "C:\Program Files\Python35\lib\site-packages\matplotlib\dates.py", line 271, in _from_ordinalf
        dt = datetime.datetime.fromordinal(ix).replace(tzinfo=UTC)
    ValueError: ordinal must be >= 1
    
  5. jusdino commented on Nov 3, 2016

    @jusdino

    Some extra info for you:

    I ran my most recently posted code (plt.show() replaced with plt.savefig('/tmp/test.png')) on a Debian system with all modules installed from the official repositories:

    • python v. 3.4.2
    • matplotlib v. 1.4.2

    It ran fine with the agg backend. Maybe this is specific to the Windows versions? I installed my Windows version of Python 3.5 from python.org but installed all of the scipy extensions as wpl packages from http://www.lfd.uci.edu/~gohlke/pythonlibs/.

  6. QuLogic commented on Nov 3, 2016

    @QuLogic
    Member

    Maybe you can run it in pdb and then print out ix at 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.

  7. tacaswell commented on Nov 3, 2016

    @tacaswell
    Member

    In the worst developer response ever 'works on my machine' 😞 (linux, anaconda py35, source installed from v1.5.3 tag)

    import matplotlib
    matplotlib.use('agg')
    import matplotlib.pyplot as plt
    import matplotlib.dates as mdates
    import datetime
    from collections import OrderedDict
    
    aggData = OrderedDict([(datetime.datetime(2016, 10, 17, 0, 0), 0.16289695106620844), (datetime.datetime(2016, 10, 18, 0, 0), 0.23634330902782563)])
    
    print('\nGenerating sample plot...')
    fig = plt.figure(figsize=(6.5,5))
    ax = fig.add_subplot(111)
    hfmt = mdates.DateFormatter('%x\n%X')
    ax.plot_date([k for k in aggData.keys()], [v for v in aggData.values()], fmt='r-')
    ax.xaxis.set_major_formatter(hfmt)
    ax.set_title(matplotlib.__version__)
    plt.xticks(rotation=60)
    fig.savefig('/tmp/test_dates.png')

    test_dates

    I wonder if this is some how windows specific?

    attn @Kojoley

  8. jusdino commented on Nov 4, 2016

    @jusdino

    @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.

  9. QuLogic commented on Nov 4, 2016

    @QuLogic
    Member

    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. Type print ix and then quit and then tell us what value it says for ix. You can also use up / down to navigate the stack frames and maybe print out other interesting variables if you want to investigate further.

  10. jusdino commented on Nov 4, 2016

    @jusdino

    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.

  11. QuLogic commented on Nov 4, 2016

    @QuLogic
    Member

    print(sys.executable) and print(matplotlib.__file__) and make sure they're all using the same files.

  12. jusdino commented on Nov 4, 2016

    @jusdino

    From PyDev console:

    >>>> print(sys.executable)
    C:\Program Files\Python35\python.exe
    >>>> print(matplotlib.__file__)
    C:\Program Files\Python35\lib\site-packages\matplotlib\__init__.py
    

    From PyDev Debugger:

    pydev debugger: starting (pid: 9960)
    C:\Program Files\Python35\python.exe
    C:\Program Files\Python35\lib\site-packages\matplotlib\__init__.py
    

    From command-line:

    >>> print(sys.executable)
    C:\Program Files\Python35\python.exe
    >>> print(matplotlib.__file__)
    C:\Program Files\Python35\lib\site-packages\matplotlib\__init__.py
    

    Looks the same to me.

  13. phobson commented on Nov 4, 2016

    @phobson
    Member

    I'll try to check this on my windows machine at work tomorrow.

  14. tacaswell commented on Nov 4, 2016

    @tacaswell
    Member

    This smells like a race condition with the auto-redraw with 'stale' and 'Agg'.

    import matplotlib
    matplotlib.use('agg')
    import matplotlib.pyplot as plt
    plt.ion()
    import matplotlib.dates as mdates
    import datetime
    from collections import OrderedDict
    
    aggData = OrderedDict([(datetime.datetime(2016, 10, 17, 0, 0), 0.16289695106620844), (datetime.datetime(2016, 10, 18, 0, 0), 0.23634330902782563)])
    
    print('\nGenerating sample plot...')
    fig = plt.figure(figsize=(6.5,5))
    ax = fig.add_subplot(111)
    hfmt = mdates.DateFormatter('%x\n%X')
    ax.plot_date([k for k in aggData.keys()], [v for v in aggData.values()], fmt='r-')
    ax.xaxis.set_major_formatter(hfmt)
    ax.set_title(matplotlib.__version__)
    plt.xticks(rotation=60)
    fig.savefig('/tmp/test_dates.png')

    If you run this as python sc2.py in fails, run it as ipython sc2.py and it succeeds. I bet in both of the OP cases mpl.rcParams['interactive'] == True via .maplotlibrc files.

  15. 1 remaining item

  16. modified the milestones: , on May 3, 2017
  17. jonathanng commented on Jul 16, 2017

    @jonathanng

    I find that this is a fix:

    matplotlib.pyplot.ion()

  18. modified the milestones: , on Oct 9, 2017
  19. kierun commented on Nov 7, 2017

    @kierun

    I think I am running into this issue as well. I am plotting a graph of the last size seconds 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:

    self.x = RingBuffer(
                ma.array(
                    [
                        now - np.timedelta64(datetime.timedelta(seconds=i))
                        for i in range(self._size)
                    ],
                    mask=self._size * [True]))
    

    Setting the formatting via:

            xfmt = matplotlib.dates.DateFormatter('%x\n%X')
            self.axes.xaxis.set_major_formatter(xfmt)
    

    Causes a ValueError: ordinal must be >= 1 when I try to draw the canvas (aka FigureCanvas(self, -1, self.figure)). The tail end of the trace is

      File "/home/usr/.virtualenvs/BTTS/lib/python3.6/site-packages/matplotlib/dates.py", line 538, in __call__
        dt = num2date(x, self.tz)
      File "/home/usr/.virtualenvs/BTTS/lib/python3.6/site-packages/matplotlib/dates.py", line 441, in num2date
        return _from_ordinalf(x, tz)
      File "/home/usr/.virtualenvs/BTTS/lib/python3.6/site-packages/matplotlib/dates.py", line 256, in _from_ordinalf
        dt = datetime.datetime.fromordinal(ix).replace(tzinfo=UTC)
    

    Where x = -0.059999999999999998 which is an odd value.

    I am running Python 3.6.3 on CentOS 7.

    Do you need anything else from me?

  20. kierun commented on Nov 7, 2017

    @kierun

    The exact same exception is raised when I call self.axes.xaxis_date()…

  21. dom96 commented on Nov 16, 2017

    @dom96

    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!

  22. dstansby commented on Nov 16, 2017

    @dstansby
    Member

    This bisects back to one of 6 commits in this PR: #4738

    aa810b6
    0af89d7
    770b8d5
    14b5a36
    69b1b36
    252d7a7

  23. kierun commented on Dec 13, 2017

    @kierun

    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.

        @value.setter
        def value(self, value):
            self.x.append(np.datetime64(datetime.datetime.now()))
            self.y.append(value[i])
            self.OnPaint(None)
    

    and

        def OnPaint(self, event):
            self.plt.set_xdata(self.x.compressed())
            self.plt.set_ydata(self.y.compressed())
            self.axes.relim()
            self.axes.autoscale_view()
            self.figure.canvas.draw()
    
  24. jklymak commented on Mar 24, 2018

    @jklymak
    Member

    I think this is closed by #10084

  25. modified the milestones: , v2.2.0 on Mar 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions