Bug summary
In Numpy 1.23.5, plt.broken_barh
happily plots X-axis values that are time-series data. Upgrading the same system to Numpy 1.24.1, it throws an exception, instead.
Code for reproduction
import numpy as np
import matplotlib.pyplot as plt
import time
plt.broken_barh(np.array([[time.time(), 1], [time.time() + 10, 2]]).astype(np.datetime64), (0, 1))
plt.show()
Actual outcome
joshua@anima:~$ python3 -m pip show numpy matplotlib
Name: numpy
Version: 1.24.1
Summary: Fundamental package for array computing in Python
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email:
License: BSD-3-Clause
Location: /home/joshua/.local/lib/python3.10/site-packages
Requires:
Required-by: contourpy, gpsrenda, h5py, imageio, matplotlib, moviepy, pandas, pyarrow, rdp
---
Name: matplotlib
Version: 3.6.2
Summary: Python plotting package
Home-page: https://matplotlib.org
Author: John D. Hunter, Michael Droettboom
Author-email: [email protected]
License: PSF
Location: /home/joshua/.local/lib/python3.10/site-packages
Requires: contourpy, cycler, fonttools, kiwisolver, numpy, packaging, pillow, pyparsing, python-dateutil
Required-by:
joshua@anima:~$ python3 broken_barh_datetime.py
Traceback (most recent call last):
File "/home/joshua/broken_barh_datetime.py", line 5, in <module>
plt.broken_barh(np.array([[time.time(), 1], [time.time() + 10, 2]]).astype(np.datetime64), (0, 1))
File "/home/joshua/.local/lib/python3.10/site-packages/matplotlib/pyplot.py", line 2428, in broken_barh
return gca().broken_barh(
File "/home/joshua/.local/lib/python3.10/site-packages/matplotlib/__init__.py", line 1423, in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)
File "/home/joshua/.local/lib/python3.10/site-packages/matplotlib/axes/_axes.py", line 2845, in broken_barh
col = mcoll.BrokenBarHCollection(xranges_conv, yrange_conv, **kwargs)
File "/home/joshua/.local/lib/python3.10/site-packages/matplotlib/collections.py", line 1256, in __init__
super().__init__(verts, **kwargs)
File "/home/joshua/.local/lib/python3.10/site-packages/matplotlib/_api/deprecation.py", line 454, in wrapper
return func(*args, **kwargs)
File "/home/joshua/.local/lib/python3.10/site-packages/matplotlib/collections.py", line 1176, in __init__
self.set_verts(verts, closed)
File "/home/joshua/.local/lib/python3.10/site-packages/matplotlib/collections.py", line 1217, in set_verts
self._paths.append(mpath.Path._create_closed(xy))
File "/home/joshua/.local/lib/python3.10/site-packages/matplotlib/path.py", line 199, in _create_closed
v = _to_unmasked_float_array(vertices)
File "/home/joshua/.local/lib/python3.10/site-packages/matplotlib/cbook/__init__.py", line 1369, in _to_unmasked_float_array
return np.asarray(x, float)
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (5, 2) + inhomogeneous part.
Expected outcome
joshua@anima:~$ python3 -m pip show numpy matplotlib
Name: numpy
Version: 1.23.5
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email:
License: BSD
Location: /home/joshua/.local/lib/python3.10/site-packages
Requires:
Required-by: contourpy, gpsrenda, h5py, imageio, matplotlib, moviepy, pandas, pyarrow, rdp
---
Name: matplotlib
Version: 3.6.2
Summary: Python plotting package
Home-page: https://matplotlib.org
Author: John D. Hunter, Michael Droettboom
Author-email: [email protected]
License: PSF
Location: /home/joshua/.local/lib/python3.10/site-packages
Requires: contourpy, cycler, fonttools, kiwisolver, numpy, packaging, pillow, pyparsing, python-dateutil
Required-by:
joshua@anima:~$ python3 broken_barh_datetime.py
shows on screen:
Additional information
matplotlib's documentation is really good and I just want to say that I appreciate it greatly!
Operating system
Ubuntu 22.04.1 LTS, x86_64
Matplotlib Version
3.6.2
Matplotlib Backend
QtAgg
Python version
Python 3.10.6
Jupyter version
No response
Installation
pip
topic: date handling topic: units and array ducktypes