Skip to content

Commit 319d837

Browse files
kinshukduavladistan
authored andcommitted
Make Line2D copy its inputs
1 parent b09aad2 commit 319d837

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/matplotlib/lines.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from .path import Path
1717
from .transforms import Bbox, BboxTransformTo, TransformedPath
1818
from ._enums import JoinStyle, CapStyle
19+
import copy
1920

2021
# Imported here for backward compatibility, even though they don't
2122
# really belong.
@@ -1230,7 +1231,7 @@ def set_xdata(self, x):
12301231
----------
12311232
x : 1D array
12321233
"""
1233-
self._xorig = x
1234+
self._xorig = copy.copy(x)
12341235
self._invalidx = True
12351236
self.stale = True
12361237

@@ -1242,7 +1243,7 @@ def set_ydata(self, y):
12421243
----------
12431244
y : 1D array
12441245
"""
1245-
self._yorig = y
1246+
self._yorig = copy.copy(y)
12461247
self._invalidy = True
12471248
self.stale = True
12481249

lib/matplotlib/tests/test_lines.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,3 +332,14 @@ def test_picking():
332332
found, indices = l2.contains(mouse_event)
333333
assert found
334334
assert_array_equal(indices['ind'], [0])
335+
336+
337+
@check_figures_equal()
338+
def test_input_copy(fig_test, fig_ref):
339+
340+
t = np.arange(0, 6, 2)
341+
l, = fig_test.add_subplot().plot(t, t, ".-")
342+
t[:] = range(3)
343+
# Trigger cache invalidation
344+
l.set_drawstyle("steps")
345+
fig_ref.add_subplot().plot([0, 2, 4], [0, 2, 4], ".-", drawstyle="steps")

0 commit comments

Comments
 (0)