# Buggy code
def _autolev(self, z, N):
    """
    Select contour levels to span the data.

    We need two more levels for filled contours than for
    line contours, because for the latter we need to specify
    the lower and upper boundary of each range. For example,
    a single contour boundary, say at z = 0, requires only
    one contour line, but two filled regions, and therefore
    three levels to provide boundaries for both regions.
    """
    if self.locator is None:
        if self.logscale:
            self.locator = ticker.LogLocator()
        else:
            self.locator = ticker.MaxNLocator(N + 1)
    zmax = self.zmax
    zmin = self.zmin
    lev = self.locator.tick_values(zmin, zmax)
    self._auto = True
    if self.filled:
        return lev
    # For line contours, drop levels outside the data range.
    return lev[(lev > zmin) & (lev < zmax)]


# Traceback (TypeError)
---------------------------------------------------------------------------
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'

# Fixed code
def _autolev(self, N):
    """
    Select contour levels to span the data.

    We need two more levels for filled contours than for
    line contours, because for the latter we need to specify
    the lower and upper boundary of each range. For example,
    a single contour boundary, say at z = 0, requires only
    one contour line, but two filled regions, and therefore
    three levels to provide boundaries for both regions.
    """
    if self.locator is None:
        if self.logscale:
            self.locator = ticker.LogLocator()
        else:
            self.locator = ticker.MaxNLocator(N + 1)
    zmax = self.zmax
    zmin = self.zmin
    lev = self.locator.tick_values(zmin, zmax)
    self._auto = True
    if self.filled:
        return lev
    # For line contours, drop levels outside the data range.
    return lev[(lev > zmin) & (lev < zmax)]