Skip to content

Commit aacc867

Browse files
authored
Merge pull request matplotlib#21490 from vladistan/line2dfix_fix
Make Line2D copy its inputs
2 parents 49609c3 + 661f7f0 commit aacc867

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

examples/units/basic_units.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ def __init__(self, value, unit):
132132
self.unit = unit
133133
self.proxy_target = self.value
134134

135+
def __copy__(self):
136+
return TaggedValue(self.value, self.unit)
137+
135138
def __getattribute__(self, name):
136139
if name.startswith('__'):
137140
return object.__getattribute__(self, name)

lib/matplotlib/lines.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
2D lines with support for a variety of line styles, markers, colors, etc.
33
"""
44

5+
import copy
6+
57
from numbers import Integral, Number, Real
68
import logging
79

@@ -1230,7 +1232,7 @@ def set_xdata(self, x):
12301232
----------
12311233
x : 1D array
12321234
"""
1233-
self._xorig = x
1235+
self._xorig = copy.copy(x)
12341236
self._invalidx = True
12351237
self.stale = True
12361238

@@ -1242,7 +1244,7 @@ def set_ydata(self, y):
12421244
----------
12431245
y : 1D array
12441246
"""
1245-
self._yorig = y
1247+
self._yorig = copy.copy(y)
12461248
self._invalidy = True
12471249
self.stale = True
12481250

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")

lib/matplotlib/tests/test_units.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ def to(self, new_units):
2626
else:
2727
return Quantity(self.magnitude, self.units)
2828

29+
def __copy__(self):
30+
return Quantity(self.magnitude, self.units)
31+
2932
def __getattr__(self, attr):
3033
return getattr(self.magnitude, attr)
3134

0 commit comments

Comments
 (0)