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

Skip to content

Commit 8d811af

Browse files
committed
Fix units support for contour and contourf
svn path=/trunk/matplotlib/; revision=8094
1 parent efe110b commit 8d811af

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

lib/matplotlib/contour.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ def __init__(self, ax, *args, **kwargs):
643643
if self.levels is None:
644644
self.levels = args[0].levels
645645
else:
646-
x, y, z = self._contour_args(*args)
646+
x, y, z = self._contour_args(args, kwargs)
647647

648648
x0 = ma.minimum(x)
649649
x1 = ma.maximum(x)
@@ -808,7 +808,7 @@ def _initialize_x_y(self, z):
808808
y = y[::-1]
809809
return np.meshgrid(x,y)
810810

811-
def _check_xyz(self, args):
811+
def _check_xyz(self, args, kwargs):
812812
'''
813813
For functions like contour, check that the dimensions
814814
of the input arrays match; if x and y are 1D, convert
@@ -817,9 +817,10 @@ def _check_xyz(self, args):
817817
Possible change: I think we should make and use an ArgumentError
818818
Exception class (here and elsewhere).
819819
'''
820-
# We can strip away the x and y units
821-
x = self.ax.convert_xunits( args[0] )
822-
y = self.ax.convert_yunits( args[1] )
820+
x, y = args[:2]
821+
self.ax._process_unit_info(xdata=x, ydata=y, kwargs=kwargs)
822+
x = self.ax.convert_xunits(x)
823+
y = self.ax.convert_yunits(y)
823824

824825
x = np.asarray(x, dtype=np.float64)
825826
y = np.asarray(y, dtype=np.float64)
@@ -840,16 +841,15 @@ def _check_xyz(self, args):
840841
return x,y,z
841842

842843

843-
844-
def _contour_args(self, *args):
844+
def _contour_args(self, args, kwargs):
845845
if self.filled: fn = 'contourf'
846846
else: fn = 'contour'
847847
Nargs = len(args)
848848
if Nargs <= 2:
849849
z = ma.asarray(args[0], dtype=np.float64)
850850
x, y = self._initialize_x_y(z)
851851
elif Nargs <=4:
852-
x,y,z = self._check_xyz(args[:3])
852+
x,y,z = self._check_xyz(args[:3], kwargs)
853853
else:
854854
raise TypeError("Too many arguments to %s; see help(%s)" % (fn,fn))
855855
z = ma.masked_invalid(z, copy=False)
@@ -1103,8 +1103,13 @@ def set_alpha(self, alpha):
11031103
are included. These added ranges are then mapped to the
11041104
special colormap values which default to the ends of the
11051105
colormap range, but can be set via
1106-
:meth:`matplotlib.cm.Colormap.set_under` and
1107-
:meth:`matplotlib.cm.Colormap.set_over` methods.
1106+
:meth:`matplotlib.colors.Colormap.set_under` and
1107+
:meth:`matplotlib.colors.Colormap.set_over` methods.
1108+
1109+
*xunits*, *yunits*: [ None | registered units ]
1110+
Override axis units by specifying an instance of a
1111+
:class:`matplotlib.units.ConversionInterface`.
1112+
11081113
11091114
contour-only keyword arguments:
11101115

0 commit comments

Comments
 (0)