Currently, Line2D doesn't copy its inputs if they are already arrays. Most of the time, in-place modifications to the input arrays do not affect the draw line, because there is a cache that doesn't get invalidated, but in some circumstances, it is possible for these modifications to affect the drawn line.
Instead, Line2D should just copy its inputs. This was rejected in #736 on a memory-saving argument, but note that AxesImage (which would typically have much bigger (2D) inputs than Line2D (which has 1D inputs)) does a copy, which if anything is much worse memory-wise.
Code for reproduction
frompylabimport*t=arange(0, 6, 2)
l, =plot(t, t, ".-")
savefig("/tmp/1.png")
t[:] =range(3) # in place changesavefig("/tmp/2.png") # no effectl.set_drawstyle("steps") # ... unless we trigger a cache invalidationsavefig("/tmp/3.png") # in fact, only the x array got updated, not the y
Actual outcome
(1)
(2) (same as (1))
(3) (different, but only x got updated, not y)
Expected outcome
Modifying t a posteriori should not affect the Line2D. Compare e.g. with AxesImage:
Hi 🙋♂️ I would like to see if I can solve the problem.
Just to make sure that I understood the expected outcome in the example. Should the y be ending in 2, right?
Bug summary
Currently, Line2D doesn't copy its inputs if they are already arrays. Most of the time, in-place modifications to the input arrays do not affect the draw line, because there is a cache that doesn't get invalidated, but in some circumstances, it is possible for these modifications to affect the drawn line.
Instead, Line2D should just copy its inputs. This was rejected in #736 on a memory-saving argument, but note that AxesImage (which would typically have much bigger (2D) inputs than Line2D (which has 1D inputs)) does a copy, which if anything is much worse memory-wise.
Code for reproduction
Actual outcome
(1)



(2) (same as (1))
(3) (different, but only x got updated, not y)
Expected outcome
Modifying
t
a posteriori should not affect the Line2D. Compare e.g. with AxesImage:Both images are identical.
Operating system
linux
Matplotlib Version
3.5b1
Matplotlib Backend
mplcairo
Python version
39
Jupyter version
No response
Other libraries
No response
Installation
source
Conda channel
No response
The text was updated successfully, but these errors were encountered: