diff --git a/lib/matplotlib/tests/test_figure.py b/lib/matplotlib/tests/test_figure.py index 5ab1f35a1a2c..88c25c54bb32 100644 --- a/lib/matplotlib/tests/test_figure.py +++ b/lib/matplotlib/tests/test_figure.py @@ -1,3 +1,4 @@ +import copy from datetime import datetime import io from pathlib import Path @@ -1261,3 +1262,28 @@ def test_kwargs_pass(): assert fig.get_label() == 'whole Figure' assert sub_fig.get_label() == 'sub figure' + + +def test_deepcopy(): + fig1, ax = plt.subplots() + ax.plot([0, 1], [2, 3]) + ax.set_yscale('log') + + fig2 = copy.deepcopy(fig1) + + # Make sure it is a new object + assert fig2.axes[0] is not ax + # And that the axis scale got propagated + assert fig2.axes[0].get_yscale() == 'log' + # Update the deepcopy and check the original isn't modified + fig2.axes[0].set_yscale('linear') + assert ax.get_yscale() == 'log' + + # And test the limits of the axes don't get propagated + ax.set_xlim(1e-1, 1e2) + # Draw these to make sure limits are updated + fig1.draw_without_rendering() + fig2.draw_without_rendering() + + assert ax.get_xlim() == (1e-1, 1e2) + assert fig2.axes[0].get_xlim() == (0, 1) diff --git a/lib/matplotlib/transforms.py b/lib/matplotlib/transforms.py index c3d1b7929128..10c127b51361 100644 --- a/lib/matplotlib/transforms.py +++ b/lib/matplotlib/transforms.py @@ -151,22 +151,6 @@ def __copy__(self): other.set_children(val) # val == getattr(other, key) return other - def __deepcopy__(self, memo): - # We could deepcopy the entire transform tree, but nothing except - # `self` is accessible publicly, so we may as well just freeze `self`. - other = self.frozen() - if other is not self: - return other - # Some classes implement frozen() as returning self, which is not - # acceptable for deepcopying, so we need to handle them separately. - other = copy.deepcopy(super(), memo) - # If `c = a + b; a1 = copy(a)`, then modifications to `a1` do not - # propagate back to `c`, i.e. we need to clear the parents of `a1`. - other._parents = {} - # If `c = a + b; c1 = copy(c)`, this creates a separate tree - # (`c1 = a1 + b1`) so nothing needs to be done. - return other - def invalidate(self): """ Invalidate this `TransformNode` and triggers an invalidation of its
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: