Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite152f02

Browse files
committed
FIX: Allow deepcopy on norms and scales
1 parent4e4410d commite152f02

File tree

5 files changed

+47
-8
lines changed

5 files changed

+47
-8
lines changed

‎doc/api/scale_api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
********************
44

55
..automodule::matplotlib.scale
6+
:private-members: _CopyableTransformMixin
67
:members:
78
:undoc-members:
89
:show-inheritance:

‎lib/matplotlib/scale.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ def limit_range_for_scale(self, vmin, vmax, minpos):
7979
returnvmin,vmax
8080

8181

82+
class_CopyableTransformMixin():
83+
"""
84+
Mixin to support copy and deep copy on transforms. This alows scales,
85+
and hence norms, to be copyable.
86+
"""
87+
def__deepcopy__(self,memo):
88+
returnself.frozen()
89+
90+
__copy__=__deepcopy__
91+
92+
8293
classLinearScale(ScaleBase):
8394
"""
8495
The default linear scale.
@@ -113,9 +124,9 @@ def get_transform(self):
113124
returnIdentityTransform()
114125

115126

116-
classFuncTransform(Transform):
127+
classFuncTransform(_CopyableTransformMixin,Transform):
117128
"""
118-
Asimpletransform that takes and arbitrary function for the
129+
A transform that takes and arbitrary function for the
119130
forward and inverse transform.
120131
"""
121132

@@ -191,7 +202,7 @@ def set_default_locators_and_formatters(self, axis):
191202
axis.set_minor_locator(NullLocator())
192203

193204

194-
classLogTransform(Transform):
205+
classLogTransform(_CopyableTransformMixin,Transform):
195206
input_dims=output_dims=1
196207

197208
@_api.rename_parameter("3.3","nonpos","nonpositive")
@@ -233,7 +244,7 @@ def inverted(self):
233244
returnInvertedLogTransform(self.base)
234245

235246

236-
classInvertedLogTransform(Transform):
247+
classInvertedLogTransform(_CopyableTransformMixin,Transform):
237248
input_dims=output_dims=1
238249

239250
def__init__(self,base):
@@ -359,7 +370,7 @@ def get_transform(self):
359370
returnself._transform
360371

361372

362-
classSymmetricalLogTransform(Transform):
373+
classSymmetricalLogTransform(_CopyableTransformMixin,Transform):
363374
input_dims=output_dims=1
364375

365376
def__init__(self,base,linthresh,linscale):
@@ -391,7 +402,7 @@ def inverted(self):
391402
self.linscale)
392403

393404

394-
classInvertedSymmetricalLogTransform(Transform):
405+
classInvertedSymmetricalLogTransform(_CopyableTransformMixin,Transform):
395406
input_dims=output_dims=1
396407

397408
def__init__(self,base,linthresh,linscale):
@@ -494,7 +505,7 @@ def get_transform(self):
494505
returnself._transform
495506

496507

497-
classLogitTransform(Transform):
508+
classLogitTransform(_CopyableTransformMixin,Transform):
498509
input_dims=output_dims=1
499510

500511
@_api.rename_parameter("3.3","nonpos","nonpositive")
@@ -520,7 +531,7 @@ def __str__(self):
520531
return"{}({!r})".format(type(self).__name__,self._nonpositive)
521532

522533

523-
classLogisticTransform(Transform):
534+
classLogisticTransform(_CopyableTransformMixin,Transform):
524535
input_dims=output_dims=1
525536

526537
@_api.rename_parameter("3.3","nonpos","nonpositive")

‎lib/matplotlib/tests/test_colors.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
importmatplotlib.colorbarasmcolorbar
1717
importmatplotlib.cbookascbook
1818
importmatplotlib.pyplotasplt
19+
importmatplotlib.scaleasmscale
1920
frommatplotlib.testing.decoratorsimportimage_comparison
2021

2122

@@ -1320,3 +1321,16 @@ def test_2d_to_rgba():
13201321
rgba_1d=mcolors.to_rgba(color.reshape(-1))
13211322
rgba_2d=mcolors.to_rgba(color.reshape((1,-1)))
13221323
assertrgba_1d==rgba_2d
1324+
1325+
1326+
deftest_norm_deepcopy():
1327+
norm=mcolors.LogNorm()
1328+
norm.vmin=0.0002
1329+
norm2=copy.deepcopy(norm)
1330+
assertnorm2.vmin==norm.vmin
1331+
assertisinstance(norm2._scale,mscale.LogScale)
1332+
norm=mcolors.Normalize()
1333+
norm.vmin=0.0002
1334+
norm2=copy.deepcopy(norm)
1335+
assertisinstance(norm2._scale,mscale.LinearScale)
1336+
assertnorm2.vmin==norm.vmin

‎lib/matplotlib/tests/test_scale.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
importnumpyasnp
99
fromnumpy.testingimportassert_allclose
10+
importcopy
1011
importio
1112
importpytest
1213

@@ -210,3 +211,9 @@ def test_pass_scale():
210211
ax.set_yscale(scale)
211212
assertax.xaxis.get_scale()=='log'
212213
assertax.yaxis.get_scale()=='log'
214+
215+
216+
deftest_scale_deepcopy():
217+
sc=mscale.LogScale(axis='x',base=10)
218+
sc2=copy.deepcopy(sc)
219+
assertstr(sc.get_transform())==str(sc2.get_transform())

‎lib/matplotlib/transforms.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,6 +2062,12 @@ def frozen(self):
20622062
# docstring inherited
20632063
returnself
20642064

2065+
def__deepcopy__(self,memo):
2066+
# The identity transform does not need to lock out deepcopy
2067+
returnself
2068+
2069+
__copy__=__deepcopy__
2070+
20652071
__str__=_make_str_method()
20662072

20672073
defget_matrix(self):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp