X Tutup
The Wayback Machine - https://web.archive.org/web/20200304102026/https://github.com/matplotlib/matplotlib/issues/16343
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyplot.stem does not support subclasses of numpy.ndarray #16343

Open
l-johnston opened this issue Jan 27, 2020 · 0 comments
Open

pyplot.stem does not support subclasses of numpy.ndarray #16343

l-johnston opened this issue Jan 27, 2020 · 0 comments
Labels

Comments

@l-johnston
Copy link

@l-johnston l-johnston commented Jan 27, 2020

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
@anntzer anntzer added the units label Jan 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.
X Tutup