Skip to content

Commit 4e80cc5

Browse files
pelsonmdboom
authored andcommitted
Fixed to contour to support the _as_mpl_transform api.
1 parent 76e0bbd commit 4e80cc5

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

lib/matplotlib/contour.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import matplotlib.mathtext as mathtext
2121
import matplotlib.patches as mpatches
2222
import matplotlib.texmanager as texmanager
23+
import matplotlib.transforms as mtrans
2324

2425
# Import needed for adding manual selection capability to clabel
2526
from matplotlib.blocking_input import BlockingContourLabeler
@@ -824,7 +825,7 @@ def __init__(self, ax, *args, **kwargs):
824825
antialiaseds = (self.antialiased,),
825826
edgecolors= 'none',
826827
alpha=self.alpha,
827-
transform=self.transform,
828+
transform=self.get_transform(),
828829
zorder=zorder)
829830
self.ax.add_collection(col)
830831
self.collections.append(col)
@@ -844,12 +845,24 @@ def __init__(self, ax, *args, **kwargs):
844845
linewidths = width,
845846
linestyle = lstyle,
846847
alpha=self.alpha,
847-
transform=self.transform,
848+
transform=self.get_transform(),
848849
zorder=zorder)
849850
col.set_label('_nolegend_')
850851
self.ax.add_collection(col, False)
851852
self.collections.append(col)
852853
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
853866

854867
def __getstate__(self):
855868
state = self.__dict__.copy()
@@ -1298,13 +1311,13 @@ def _process_args(self, *args, **kwargs):
12981311
_mask = None
12991312
C = _cntr.Cntr(x, y, z.filled(), _mask)
13001313

1301-
t = self.ax.transData if self.transform is None else self.transform
1314+
t = self.get_transform()
13021315

13031316
# if the transform is not trans data, and some part of it
13041317
# contains transData, transform the xs and ys to data coordinates
13051318
if (t != self.ax.transData and
13061319
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
13081321
pts = (np.vstack([x.flat, y.flat]).T)
13091322
transformed_pts = trans_to_data.transform(pts)
13101323
x = transformed_pts[..., 0]

0 commit comments

Comments
 (0)