-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed
Labels
Good first issueOpen a pull request against these issues if there are no active ones!Open a pull request against these issues if there are no active ones!status: has patchpatch suggested, PR still neededpatch suggested, PR still neededtopic: date handling
Milestone
Description
Bug summary
pyplot raises an error when a list of dates starts with None.
Code for reproduction
from datetime import *
from matplotlib import pyplot as plt
y = [6, 2, 8, 3, 1, 8, 5, 3, 0, 7]
x = [date.today() + timedelta(days=i) for i in range(10)]
x[5] = None
x[-1] = None
plt.plot(x, y) # works
plt.show()
x[0] = None
plt.plot(x, y) # TypeError
plt.show()
Actual outcome
Traceback (most recent call last):
File "pyplot_test.py", line 17, in <module>
plt.plot(x, y)
File "<python_path>\lib\site-packages\matplotlib\pyplot.py", line 2769, in plot
return gca().plot(
File "<python_path>\lib\site-packages\matplotlib\axes\_axes.py", line 1634, in plot
self.add_line(line)
File "<python_path>\lib\site-packages\matplotlib\axes\_base.py", line 2288, in add_line
self._update_line_limits(line)
File "<python_path>\lib\site-packages\matplotlib\axes\_base.py", line 2311, in _update_line_limits
path = line.get_path()
File "<python_path>\lib\site-packages\matplotlib\lines.py", line 999, in get_path
self.recache()
File "<python_path>\lib\site-packages\matplotlib\lines.py", line 652, in recache
x = _to_unmasked_float_array(xconv).ravel()
File "<python_path>\lib\site-packages\matplotlib\cbook\__init__.py", line 1298, in _to_unmasked_float_array
return np.asarray(x, float)
File "<python_path>\lib\site-packages\numpy\core\_asarray.py", line 85, in asarray
return array(a, dtype, copy=False, order=order)
TypeError: float() argument must be a string or a number, not 'datetime.date'
Expected outcome
plot data starting at index 1.
Additional information
No response
Operating system
windows 10
Matplotlib Version
3.5.2
Matplotlib Backend
TkAgg
Python version
3.8.2
Jupyter version
No response
Installation
pip
Metadata
Metadata
Assignees
Labels
Good first issueOpen a pull request against these issues if there are no active ones!Open a pull request against these issues if there are no active ones!status: has patchpatch suggested, PR still neededpatch suggested, PR still neededtopic: date handling