Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Datetime plot fails with 'Agg' backend in interactive mode #15409

Copy link
Copy link
Closed
@fanxinping

Description

@fanxinping
Issue body actions

Bug report

Bug summary

I try to plot the time series data, and the X-axis represents the datetime. The code succeeds when use the 'Qt5Agg' backend, but fails when use the 'Agg' backend
Code for reproduction
The example code based on the matplotlib tutorials(https://matplotlib.org/3.1.1/gallery/ticks_and_spines/date_concise_formatter.html).
When use the 'Qt5Agg' backend, the code works well.(To show my issue, I use the python instead of ipython, because the ipython will use 'Qt5Agg' backend as default in my ENV)

Python 3.6.8 (default, Oct  7 2019, 12:59:55) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> import matplotlib.pyplot as plt
>>> import matplotlib.dates as mdates
>>> import numpy as np
>>> base = datetime.datetime(2005, 2, 1)
>>> dates = np.array([base + datetime.timedelta(hours=(2 * i)) for i in range(732)])
>>> np.random.seed(19680801)
>>> N = len(dates)
>>> y = np.cumsum(np.random.randn(N))
>>> import matplotlib
>>> matplotlib.get_backend()
'Qt5Agg'
>>> plt.plot(dates,y)
[<matplotlib.lines.Line2D object at 0x7f621c039828>]

And I get the expected figure.
Figure_1
But when I use 'Agg' backend, the code fails.

Python 3.6.8 (default, Oct  7 2019, 12:59:55) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> matplotlib.use('Agg')
>>> matplotlib.get_backend()
'agg'
>>> import datetime
>>> import matplotlib.pyplot as plt
>>> import matplotlib.dates as mdates
>>> import numpy as np
>>> base = datetime.datetime(2005, 2, 1)
>>> dates = np.array([base + datetime.timedelta(hours=(2 * i)) for i in range(732)])
>>> N = len(dates)
>>> np.random.seed(19680801)
>>> y = np.cumsum(np.random.randn(N))
>>> plt.plot(dates,y)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/pyplot.py", line 2795, in plot
    is not None else {}), **kwargs)
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/axes/_axes.py", line 1666, in plot
    lines = [*self._get_lines(*args, data=data, **kwargs)]
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 225, in __call__
    yield from self._plot_args(this, kwargs)
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 391, in _plot_args
    x, y = self._xy_from_xy(x, y)
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 243, in _xy_from_xy
    bx = self.axes.xaxis.update_units(x)
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/axis.py", line 1498, in update_units
    self._update_axisinfo()
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/axis.py", line 1516, in _update_axisinfo
    self.set_major_locator(info.majloc)
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/axis.py", line 1651, in set_major_locator
    self.stale = True
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/artist.py", line 230, in stale
    self.stale_callback(self, val)
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/artist.py", line 51, in _stale_axes_callback
    self.axes.stale = val
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/artist.py", line 230, in stale
    self.stale_callback(self, val)
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/figure.py", line 51, in _stale_figure_callback
    self.figure.stale = val
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/artist.py", line 230, in stale
    self.stale_callback(self, val)
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/pyplot.py", line 589, in _auto_draw_if_interactive
    fig.canvas.draw_idle()
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 1907, in draw_idle
    self.draw(*args, **kwargs)
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 388, in draw
    self.figure.draw(self.renderer)
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/figure.py", line 1709, in draw
    renderer, self, artists, self.suppressComposite)
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/image.py", line 135, in _draw_list_compositing_images
    a.draw(renderer)
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 2647, in draw
    mimage._draw_list_compositing_images(renderer, self, artists)
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/image.py", line 135, in _draw_list_compositing_images
    a.draw(renderer)
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/axis.py", line 1203, in draw
    ticks_to_draw = self._update_ticks()
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/axis.py", line 1079, in _update_ticks
    major_locs = self.get_majorticklocs()
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/axis.py", line 1324, in get_majorticklocs
    return self.major.locator()
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/dates.py", line 1431, in __call__
    self.refresh()
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/dates.py", line 1451, in refresh
    dmin, dmax = self.viewlim_to_dt()
  File "/home/fanxp/.local/lib/python3.6/site-packages/matplotlib/dates.py", line 1202, in viewlim_to_dt
    .format(vmin))
ValueError: view limit minimum 0.0 is less than 1 and is an invalid Matplotlib date value. This often happens if you pass a non-datetime value to an axis that has datetime units
>>>

So, how can I resolve this issue? Thanks!

Matplotlib version

  • Operating system: ubuntu 18.04
  • Matplotlib version: 3.1.1
  • Matplotlib backend (print(matplotlib.get_backend())): agg
  • Python version: 3.6.8
  • Jupyter version (if applicable):
  • Other libraries: numpy 1.17.2

I use pip to install numpy and matplotlib, and I use the system's python3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.