Description
Bug report
Bug summary
pyplot.stem does not support subclasses of numpy.ndarray that have defined the matplotlib.units.ConversionInterface. In the example below, I am using the unyt library where unyt_array
is a np.ndarray subclass and the library has defined the units.ConversionInterface. pyplot.plot works as expected, but pyplot.stem never calls the ConversionInterface.
The problem is in _axes.py in the first line of pyplot.stem where y = np.asarray(y)
converts the unyt_array
to a pure np.ndarray and the subsequent line y = self.convert_yunits(y)
never calls the ConversionInterface because y is now a np.ndarray. Changing the first line to y = np.asanyarray(y)
fixes the problem allowing the subclass to pass through.
Is it possible for matplotlib to update pyplot.stem to support np.ndarray subclasses?
Code for reproduction
>>> import matplotlib.pyplot as plt
>>> import unyt
>>> unyt.matplotlib_support()
>>> y = unyt.unyt_array([1,2,3], "m", name="length")
>>> fig, ax = plt.subplots()
>>> ax.stem(y)
>>> ax.yaxis.get_label().get_text()
Actual outcome
''
Expected outcome
'$\\left(\\rm{m}\\right)$'
Matplotlib version
- Operating system: Linux
- Matplotlib version: 3.1.2
- Matplotlib backend (
print(matplotlib.get_backend())
): TkAgg - Python version: 3.6.9
- Jupyter version (if applicable):
- Other libraries: unyt: 2.6.0