Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Bug]: Enforce that Line data modifications are sequences #28927

Copy link
Copy link
Closed
@andyfaff

Description

@andyfaff
Issue body actions

Bug summary

It used to be possible to use Line2D.set_ydata with a single scalar. From a quick search I think this behaviour was changed in #22329, and I guess it makes sense for a lot of cases. However, I don't think mandating a sequence really makes sense when Line2D was created by ax.axhline, or ax.axvline, because those two methods use scalars themselves, not sequences.

Code for reproduction

fig, ax = plt.subplots()
l = ax.axvline(x=10)
l.set_xdata(15)

Actual outcome

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[8], line 4
      2 fig, ax = plt.subplots()
      3 l = ax.axvline(x=10)
----> 4 l.set_xdata(15)

File [~/miniforge3/envs/dev3/lib/python3.12/site-packages/matplotlib/lines.py:1289](http://localhost:8888/lab/tree/data/reduce/~/miniforge3/envs/dev3/lib/python3.12/site-packages/matplotlib/lines.py#line=1288), in Line2D.set_xdata(self, x)
   1276 """
   1277 Set the data array for x.
   1278 
   (...)
   1286 set_ydata
   1287 """
   1288 if not np.iterable(x):
-> 1289     raise RuntimeError('x must be a sequence')
   1290 self._xorig = copy.copy(x)
   1291 self._invalidx = True

RuntimeError: x must be a sequence

Expected outcome

A plot with horizontal/vertical line

Additional information

No response

Operating system

No response

Matplotlib Version

3.9.2

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.