Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
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