File tree 2 files changed +26
-16
lines changed
2 files changed +26
-16
lines changed Original file line number Diff line number Diff line change
1
+ import copy
1
2
from datetime import datetime
2
3
import io
3
4
from pathlib import Path
@@ -1282,3 +1283,28 @@ def test_kwargs_pass():
1282
1283
1283
1284
assert fig .get_label () == 'whole Figure'
1284
1285
assert sub_fig .get_label () == 'sub figure'
1286
+
1287
+
1288
+ def test_deepcopy ():
1289
+ fig1 , ax = plt .subplots ()
1290
+ ax .plot ([0 , 1 ], [2 , 3 ])
1291
+ ax .set_yscale ('log' )
1292
+
1293
+ fig2 = copy .deepcopy (fig1 )
1294
+
1295
+ # Make sure it is a new object
1296
+ assert fig2 .axes [0 ] is not ax
1297
+ # And that the axis scale got propagated
1298
+ assert fig2 .axes [0 ].get_yscale () == 'log'
1299
+ # Update the deepcopy and check the original isn't modified
1300
+ fig2 .axes [0 ].set_yscale ('linear' )
1301
+ assert ax .get_yscale () == 'log'
1302
+
1303
+ # And test the limits of the axes don't get propagated
1304
+ ax .set_xlim (1e-1 , 1e2 )
1305
+ # Draw these to make sure limits are updated
1306
+ fig1 .draw_without_rendering ()
1307
+ fig2 .draw_without_rendering ()
1308
+
1309
+ assert ax .get_xlim () == (1e-1 , 1e2 )
1310
+ assert fig2 .axes [0 ].get_xlim () == (0 , 1 )
Original file line number Diff line number Diff line change @@ -151,22 +151,6 @@ def __copy__(self):
151
151
other .set_children (val ) # val == getattr(other, key)
152
152
return other
153
153
154
- def __deepcopy__ (self , memo ):
155
- # We could deepcopy the entire transform tree, but nothing except
156
- # `self` is accessible publicly, so we may as well just freeze `self`.
157
- other = self .frozen ()
158
- if other is not self :
159
- return other
160
- # Some classes implement frozen() as returning self, which is not
161
- # acceptable for deepcopying, so we need to handle them separately.
162
- other = copy .deepcopy (super (), memo )
163
- # If `c = a + b; a1 = copy(a)`, then modifications to `a1` do not
164
- # propagate back to `c`, i.e. we need to clear the parents of `a1`.
165
- other ._parents = {}
166
- # If `c = a + b; c1 = copy(c)`, this creates a separate tree
167
- # (`c1 = a1 + b1`) so nothing needs to be done.
168
- return other
169
-
170
154
def invalidate (self ):
171
155
"""
172
156
Invalidate this `TransformNode` and triggers an invalidation of its
You can’t perform that action at this time.
0 commit comments