Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fixed to contour to support the _as_mpl_transform api. #1293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 21, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions doc/api/api_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ Changes in 1.2.x
>>> print(ax.viewLim)
Bbox('array([[ 0., 0.],\n [ 90., 90.]])')

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

>>> import matplotlib.pyplot as plt
>>> ax = plt.axes()
Expand All @@ -126,9 +126,9 @@ Changes in 1.2.x
>>> print(data2ax.depth)
2

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

* ``twinx`` and ``twiny`` now returns an instance of SubplotBase if
parent axes is an instance of SubplotBase.
Expand All @@ -141,6 +141,9 @@ Changes in 1.2.x
* :class:`~matplotlib.colors.ColorConverter`,
:class:`~matplotlib.colors.Colormap` and
:class:`~matplotlib.colors.Normalize` now subclasses ``object``

* ContourSet instances no longer have a ``transform`` attribute. Instead,
access the transform with the ``get_transform`` method.

Changes in 1.1.x
================
Expand Down
23 changes: 18 additions & 5 deletions lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import matplotlib.mathtext as mathtext
import matplotlib.patches as mpatches
import matplotlib.texmanager as texmanager
import matplotlib.transforms as mtrans

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

self.transform = kwargs.get('transform', None)
self._transform = kwargs.get('transform', None)

self._process_args(*args, **kwargs)
self._process_levels()
Expand Down Expand Up @@ -824,7 +825,7 @@ def __init__(self, ax, *args, **kwargs):
antialiaseds = (self.antialiased,),
edgecolors= 'none',
alpha=self.alpha,
transform=self.transform,
transform=self.get_transform(),
zorder=zorder)
self.ax.add_collection(col)
self.collections.append(col)
Expand All @@ -844,12 +845,24 @@ def __init__(self, ax, *args, **kwargs):
linewidths = width,
linestyle = lstyle,
alpha=self.alpha,
transform=self.transform,
transform=self.get_transform(),
zorder=zorder)
col.set_label('_nolegend_')
self.ax.add_collection(col, False)
self.collections.append(col)
self.changed() # set the colors

def get_transform(self):
"""
Return the :class:`~matplotlib.transforms.Transform`
instance used by this ContourSet.
"""
if self._transform is None:
self._transform = self.ax.transData
elif (not isinstance(self._transform, mtrans.Transform)
and hasattr(self._transform, '_as_mpl_transform')):
self._transform = self._transform._as_mpl_transform(self.ax)
return self._transform

def __getstate__(self):
state = self.__dict__.copy()
Expand Down Expand Up @@ -1298,13 +1311,13 @@ def _process_args(self, *args, **kwargs):
_mask = None
C = _cntr.Cntr(x, y, z.filled(), _mask)

t = self.ax.transData if self.transform is None else self.transform
t = self.get_transform()

# if the transform is not trans data, and some part of it
# contains transData, transform the xs and ys to data coordinates
if (t != self.ax.transData and
any(t.contains_branch_seperately(self.ax.transData))):
trans_to_data = self.transform - self.ax.transData
trans_to_data = t - self.ax.transData
pts = (np.vstack([x.flat, y.flat]).T)
transformed_pts = trans_to_data.transform(pts)
x = transformed_pts[..., 0]
Expand Down