Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[Bug]: Inconsistency as to whether Line2D.get_data() preserves types of input sequences #28854

Open
@anntzer

Description

@anntzer

Bug summary

Line2D.get_data() returns sequences coerced to arrays when the line is constructed via plot(), but the original sequence objects when data is updated using Line2D.set_data().

Code for reproduction

frompylabimport*classT(list):passl,=plt.plot([],T())x,y=l.get_data()print(type(x),type(y))# prints ndarray, ndarrayl.set_data([],T())x,y=l.get_data()print(type(x),type(y))# prints list, T

Actual outcome

<class 'numpy.ndarray'> <class 'numpy.ndarray'>
<class 'list'> <class 'main.T'>

Expected outcome

either ndarray in all cases (my preference), or the original type in all cases.

Additional information

I noticed the problem because I was relying on the implicit conversion to ndarray so that I could directly call some array methods later on the values returned by get_data(); later trying to update the data with set_data() (in a dynamic plot) let to a crash because these inputs were no longer converted.

My preference is that everything should be cast to ndarrays (we don't want to keep alive arbitrary array subclasses which may e.g. be memmaps or whatnot), but always keeping the input type would be fine too; being consistent is the more important point.

Operating system

macos

Matplotlib Version

3.10.0.dev645+gcb9cf3bbb1

Matplotlib Backend

any

Python version

3.12.2

Jupyter version

enosuchlib

Installation

git checkout

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp