-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Closed
Description
Hello. Code using matplotlib.ticker.LinearLocator() with pyplot.contour() does not work anymore. I have tested other matplotlib.ticker subclasses (such as LogLocator() and AutoLocator()) which have worked fine. Please see the attached example and debug trace.
Thank you,
Nathaniel
Matplotlib version: 1.5.1 (installed by cloning git repository, then using sudo pip install -e .)
Python version: Python 2.7.3 (default, Jun 22 2015, 19:33:41)
Platform: Ubuntu 12.04
Example based on: http://matplotlib.org/examples/pylab_examples/contour_demo.html
#!/usr/bin/env python
"""
Illustrate simple contour plotting, contours on an image with
a colorbar for the contours, and labelled contours.
See also contour_image.py.
"""
import matplotlib
import numpy as np
import matplotlib.cm as cm
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
matplotlib.rcParams['xtick.direction'] = 'out'
matplotlib.rcParams['ytick.direction'] = 'out'
delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
# difference of Gaussians
Z = 10.0 * (Z2 - Z1)
# Create a simple contour plot with labels using default colors. The
# inline argument to clabel will control whether the labels are draw
# over the line segments of the contour, removing the lines beneath
# the label
plt.figure()
CS = plt.contour(X, Y, Z,locator=matplotlib.ticker.LinearLocator(10))
plt.clabel(CS, inline=1, fontsize=10)
plt.title('Simplest default with labels')Output trace:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-13-37a1d06c84a1> in <module>()
30 # the label
31 plt.figure()
---> 32 CS = plt.contour(X, Y, Z,locator=matplotlib.ticker.LinearLocator(10))
33 plt.clabel(CS, inline=1, fontsize=10)
34 plt.title('Simplest default with labels')
/home/w2naf/code/matplotlib/lib/matplotlib/pyplot.pyc in contour(*args, **kwargs)
2764 ax.hold(hold)
2765 try:
-> 2766 ret = ax.contour(*args, **kwargs)
2767 finally:
2768 ax.hold(washold)
/home/w2naf/code/matplotlib/lib/matplotlib/__init__.pyc in inner(ax, *args, **kwargs)
1810 warnings.warn(msg % (label_namer, func.__name__),
1811 RuntimeWarning, stacklevel=2)
-> 1812 return func(ax, *args, **kwargs)
1813 pre_doc = inner.__doc__
1814 if pre_doc is None:
/home/w2naf/code/matplotlib/lib/matplotlib/axes/_axes.pyc in contour(self, *args, **kwargs)
5642 self.cla()
5643 kwargs['filled'] = False
-> 5644 return mcontour.QuadContourSet(self, *args, **kwargs)
5645 contour.__doc__ = mcontour.QuadContourSet.contour_doc
5646
/home/w2naf/code/matplotlib/lib/matplotlib/contour.pyc in __init__(self, ax, *args, **kwargs)
1422 are described in QuadContourSet.contour_doc.
1423 """
-> 1424 ContourSet.__init__(self, ax, *args, **kwargs)
1425
1426 def _process_args(self, *args, **kwargs):
/home/w2naf/code/matplotlib/lib/matplotlib/contour.pyc in __init__(self, ax, *args, **kwargs)
861 self._transform = kwargs.get('transform', None)
862
--> 863 self._process_args(*args, **kwargs)
864 self._process_levels()
865
/home/w2naf/code/matplotlib/lib/matplotlib/contour.pyc in _process_args(self, *args, **kwargs)
1443 self._corner_mask = mpl.rcParams['contour.corner_mask']
1444
-> 1445 x, y, z = self._contour_args(args, kwargs)
1446
1447 _mask = ma.getmask(z)
/home/w2naf/code/matplotlib/lib/matplotlib/contour.pyc in _contour_args(self, args, kwargs)
1538 warnings.warn('Log scale: values of z <= 0 have been masked')
1539 self.zmin = z.min()
-> 1540 self._contour_level_args(z, args)
1541 return (x, y, z)
1542
/home/w2naf/code/matplotlib/lib/matplotlib/contour.pyc in _contour_level_args(self, z, args)
1167 if self.levels is None:
1168 if len(args) == 0:
-> 1169 lev = self._autolev(z, 7)
1170 else:
1171 level_arg = args[0]
/home/w2naf/code/matplotlib/lib/matplotlib/contour.pyc in _autolev(self, z, N)
1149 zmax = self.zmax
1150 zmin = self.zmin
-> 1151 lev = self.locator.tick_values(zmin, zmax)
1152 self._auto = True
1153 if self.filled:
/home/w2naf/code/matplotlib/lib/matplotlib/ticker.pyc in tick_values(self, vmin, vmax)
1173 vmin, vmax = vmax, vmin
1174
-> 1175 if (vmin, vmax) in self.presets:
1176 return self.presets[(vmin, vmax)]
1177
TypeError: unhashable type: 'MaskedArray'Reactions are currently unavailable