8000 Merge pull request #1293 from pelson/trans_api_fix · cirosantilli/matplotlib@58a933f · GitHub
[go: up one dir, main page]

Skip to content

Commit 58a933f

Browse files
committed
Merge pull request matplotlib#1293 from pelson/trans_api_fix
Fixed to contour to support the _as_mpl_transform api.
2 parents 1f331db + ddd77f6 commit 58a933f

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

doc/api/api_changes.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ Changes in 1.2.x
114114
>>> print(ax.viewLim)
115115
Bbox('array([[ 0., 0.],\n [ 90., 90.]])')
116116

117-
* One can now easily get a transform which goes from one transform's coordinate system
118-
to another, in an optimized way, using the new subtract method on a transform. For instance,
119-
to go from data coordinates to axes coordinates::
117+
* One can now easily get a transform which goes from one transform's coordinate
118+
system to another, in an optimized way, using the new subtract method on a
119+
transform. For instance, to go from data coordinates to axes coordinates::
120120

121121
>>> import matplotlib.pyplot as plt
122122
>>> ax = plt.axes()
@@ -126,9 +126,9 @@ Changes in 1.2.x
126126
>>> print(data2ax.depth)
127127
2
128128

129-
for versions before 1.2 this could only be achieved in a sub-optimal way, using
130-
``ax.transData + ax.transAxes.inverted()`` (depth is a new concept, but had it existed
131-
it would return 4 for this example).
129+
for versions before 1.2 this could only be achieved in a sub-optimal way,
130+
using ``ax.transData + ax.transAxes.inverted()`` (depth is a new concept,
131+
but had it existed it would return 4 for this example).
132132

133133
* ``twinx`` and ``twiny`` now returns an instance of SubplotBase if
134134
parent axes is an instance of SubplotBase.
@@ -141,6 +141,9 @@ Changes in 1.2.x
141141
* :class:`~matplotlib.colors.ColorConverter`,
142142
:class:`~matplotlib.colors.Colormap` and
143143
:class:`~matplotlib.colors.Normalize` now subclasses ``object``
144+
145+
* ContourSet instances no longer have a ``transform`` attribute. Instead,
146+
access the transform with the ``get_transform`` method.
144147

145148
Changes in 1.1.x
146149
================

lib/matplotlib/contour.py

Lines changed: 18 additions & 5 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< 8000 /td>+
import matplotlib.transforms as mtrans
2324

2425
# Import needed for adding manual selection capability to clabel
2526
from matplotlib.blocking_input import BlockingContourLabeler
@@ -774,7 +775,7 @@ def __init__(self, ax, *args, **kwargs):
774775
raise ValueError('Either colors or cmap must be None')
775776
if self.origin == 'image': self.origin = mpl.rcParams['image.origin']
776777

777-
self.transform = kwargs.get('transform', None)
778+
self._transform = kwargs.get('transform', None)
778779

779780
self._process_args(*args, **kwargs)
780781
self._process_levels()
@@ -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)
0