Skip to content

[Bug]: v3.5.2 causing plot to crash when plotting object with __array__ method #22973

Closed
@WilliamJamieson

Description

@WilliamJamieson

Bug summary

In astropy/astropy#13209 a potential bug with v3.5.2 has been found wherein a previously working (e.g. in v3.5.1) plot of one of kernel objects now fails. This failure seems to stem from plot no-longer coercing the the kernel object correctly. This seems to be related to the changes in #22141. In any case we have an object with a valid __array__ method which was previously plotting correctly, but now produces a crash.

Code for reproduction

import matplotlib.pyplot as plt 
from astropy.convolution import Gaussian1DKernel 
gauss_1D_kernel = Gaussian1DKernel(10) 
plt.plot(gauss_1D_kernel, drawstyle='steps')

Actual outcome

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/astropy/envs/12943/lib/python3.9/site-packages/matplotlib/sphinxext/plot_directive.py", line 517, in _run_code
    exec(code, ns)
  File "<string>", line 4, in <module>
  File "/home/docs/checkouts/readthedocs.org/user_builds/astropy/envs/12943/lib/python3.9/site-packages/matplotlib/pyplot.py", line 2769, in plot
    return gca().plot(
  File "/home/docs/checkouts/readthedocs.org/user_builds/astropy/envs/12943/lib/python3.9/site-packages/matplotlib/axes/_axes.py", line 1632, in plot
    lines = [*self._get_lines(*args, data=data, **kwargs)]
  File "/home/docs/checkouts/readthedocs.org/user_builds/astropy/envs/12943/lib/python3.9/site-packages/matplotlib/axes/_base.py", line 312, in __call__
    yield from self._plot_args(this, kwargs)
  File "/home/docs/checkouts/readthedocs.org/user_builds/astropy/envs/12943/lib/python3.9/site-packages/matplotlib/axes/_base.py", line 500, in _plot_args
    if x.ndim > 2 or y.ndim > 2:

Expected outcome

See: https://docs.astropy.org/en/latest/_images/astropy-convolution-Gaussian1DKernel-1.png

Additional information

No response

Operating system

No response

Matplotlib Version

3.5.2

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions