20
20
import matplotlib .mathtext as mathtext
21
21
import matplotlib .patches as mpatches
22
22
import matplotlib .texmanager as texmanager
23
<
8000
/td>+ import matplotlib .transforms as mtrans
23
24
24
25
# Import needed for adding manual selection capability to clabel
25
26
from matplotlib .blocking_input import BlockingContourLabeler
@@ -774,7 +775,7 @@ def __init__(self, ax, *args, **kwargs):
774
775
raise ValueError ('Either colors or cmap must be None' )
775
776
if self .origin == 'image' : self .origin = mpl .rcParams ['image.origin' ]
776
777
777
- self .transform = kwargs .get ('transform' , None )
778
+ self ._transform = kwargs .get ('transform' , None )
778
779
779
780
self ._process_args (* args , ** kwargs )
780
781
self ._process_levels ()
@@ -824,7 +825,7 @@ def __init__(self, ax, *args, **kwargs):
824
825
antialiaseds = (self .antialiased ,),
825
826
edgecolors = 'none' ,
826
827
alpha = self .alpha ,
827
- transform = self .transform ,
828
+ transform = self .get_transform () ,
828
829
zorder = zorder )
829
830
self .ax .add_collection (col )
830
831
self .collections .append (col )
@@ -844,12 +845,24 @@ def __init__(self, ax, *args, **kwargs):
844
845
linewidths = width ,
845
846
linestyle = lstyle ,
846
847
alpha = self .alpha ,
847
- transform = self .transform ,
848
+ transform = self .get_transform () ,
848
849
zorder = zorder )
849
850
col .set_label ('_nolegend_' )
850
851
self .ax .add_collection (col , False )
851
852
self .collections .append (col )
852
853
self .changed () # set the colors
854
+
855
+ def get_transform (self ):
856
+ """
857
+ Return the :class:`~matplotlib.transforms.Transform`
858
+ instance used by this ContourSet.
859
+ """
860
+ if self ._transform is None :
861
+ self ._transform = self .ax .transData
862
+ elif (not isinstance (self ._transform , mtrans .Transform )
863
+ and hasattr (self ._transform , '_as_mpl_transform' )):
864
+ self ._transform = self ._transform ._as_mpl_transform (self .ax )
865
+ return self ._transform
853
866
854
867
def __getstate__ (self ):
855
868
state = self .__dict__ .copy ()
@@ -1298,13 +1311,13 @@ def _process_args(self, *args, **kwargs):
1298
1311
_mask = None
1299
1312
C = _cntr .Cntr (x , y , z .filled (), _mask )
1300
1313
1301
- t = self .ax . transData if self . transform is None else self . transform
1314
+ t = self .get_transform ()
1302
1315
1303
1316
# if the transform is not trans data, and some part of it
1304
1317
# contains transData, transform the xs and ys to data coordinates
1305
1318
if (t != self .ax .transData and
1306
1319
any (t .contains_branch_seperately (self .ax .transData ))):
1307
- trans_to_data = self . transform - self .ax .transData
1320
+ trans_to_data = t - self .ax .transData
1308
1321
pts = (np .vstack ([x .flat , y .flat ]).T )
1309
1322
transformed_pts = trans_to_data .transform (pts )
1310
1323
x = transformed_pts [..., 0 ]
0 commit comments