8000 Plot with dates cannot follow axhline · Issue #17925 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Plot with dates cannot follow axhline #17925
Closed
@efiring

Description

@efiring

Bug report

Bug summary

A call to axhline followed by plotting with dates yields an exception.

This arises when trying to reproduce #7742.

Code for reproduction

import matplotlib.pyplot as plt
from datetime import datetime

fig, ax = plt.subplots()

ax.axhline(1.5)
ax.plot([datetime(2016, 1, 1, 0, 0, 0), datetime(2016, 1, 2, 0, 0, 0)], [1, 2])

Actual outcome

TypeError                                 Traceback (most recent call last)
<ipython-input-5-02e4fc5c74c6> in <module>
      5
      6 ax.axhline(1.5)
----> 7 ax.plot([datetime(2016, 1, 1, 0, 0, 0), datetime(2016, 1, 2, 0, 0, 0)], [1, 2])

~/work/programs/py/mpl/matplotlib/lib/matplotlib/axes/_axes.py in plot(self, scalex, scaley, data, *args, **kwargs)
   1743         lines = [*self._get_lines(*args, data=data, **kwargs)]
   1744         for line in lines:
-> 1745             self.add_line(line)
   1746         self._request_autoscale_view(scalex=scalex, scaley=scaley)
   1747         return lines

~/work/programs/py/mpl/matplotlib/lib/matplotlib/axes/_base.py in add_line(self, line)
   1975             line.set_clip_path(self.patch)
   1976
-> 1977         self._update_line_limits(line)
   1978         if not line.get_label():
   1979             line.set_label('_line%d' % len(self.lines))

~/work/programs/py/mpl/matplotlib/lib/matplotlib/axes/_base.py in _update_line_limits(self, line)
   1997         Figures out the data limit of the given line, updating self.dataLim.
   1998         """
-> 1999         path = line.get_path()
   2000         if path.vertices.size == 0:
   2001             return

~/work/programs/py/mpl/matplotlib/lib/matplotlib/lines.py in get_path(self)
   1009         """
   1010         if self._invalidy or self._invalidx:
-> 1011             self.recache()
   1012         return self._path
   1013

~/work/programs/py/mpl/matplotlib/lib/matplotlib/lines.py in recache(self, always)
    651         if always or self._invalidx:
    652             xconv = self.convert_xunits(self._xorig)
--> 653             x = _to_unmasked_float_array(xconv).ravel()
    654         else:
    655             x = self._x

~/work/programs/py/mpl/matplotlib/lib/matplotlib/cbook/__init__.py in _to_unmasked_float_array(x)
   1296         return np.ma.asarray(x, float).filled(np.nan)
   1297     else:
-> 1298         return np.asarray(x, float)
   1299
   1300
~/miniconda3/envs/mpl1/lib/python3.7/site-packages/numpy/core/_asarray.py in asarray(a, dtype, order)
     83
     84     """
---> 85     return array(a, dtype, copy=False, order=order)
     86
     87

TypeError: float() argument must be a string or a number, not 'datetime.datetime'

Expected outcome
A plot, with or without the bug from #7742.

Matplotlib version

  • Matplotlib version: 3.3.0rc1.post273+gb803891a4b

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0