Skip to content

Commit

Permalink
Merge pull request #4718 from Carreau/global-interpolation
Browse files Browse the repository at this point in the history
Expose interpolation short names at module level.
  • Loading branch information
WeatherGod committed Jul 22, 2015
2 parents 1097e3f + 743876c commit b1b4fb8
Showing 1 changed file with 35 additions and 28 deletions.
63 changes: 35 additions & 28 deletions lib/matplotlib/image.py
Expand Up @@ -34,35 +34,42 @@
from matplotlib.transforms import BboxBase, Bbox, IdentityTransform
import matplotlib.transforms as mtransforms

# map interpolation strings to module constants
_interpd_ = {
'none': _image.NEAREST, # fall back to nearest when not supported
'nearest': _image.NEAREST,
'bilinear': _image.BILINEAR,
'bicubic': _image.BICUBIC,
'spline16': _image.SPLINE16,
'spline36': _image.SPLINE36,
'hanning': _image.HANNING,
'hamming': _image.HAMMING,
'hermite': _image.HERMITE,
'kaiser': _image.KAISER,
'quadric': _image.QUADRIC,
'catrom': _image.CATROM,
'gaussian': _image.GAUSSIAN,
'bessel': _image.BESSEL,
'mitchell': _image.MITCHELL,
'sinc': _image.SINC,
'lanczos': _image.LANCZOS,
'blackman': _image.BLACKMAN,
}


interpolations_names = set(six.iterkeys(_interpd_))


class _AxesImageBase(martist.Artist, cm.ScalarMappable):
zorder = 0
# map interpolation strings to module constants
_interpd = {
'none': _image.NEAREST, # fall back to nearest when not supported
'nearest': _image.NEAREST,
'bilinear': _image.BILINEAR,
'bicubic': _image.BICUBIC,
'spline16': _image.SPLINE16,
'spline36': _image.SPLINE36,
'hanning': _image.HANNING,
'hamming': _image.HAMMING,
'hermite': _image.HERMITE,
'kaiser': _image.KAISER,
'quadric': _image.QUADRIC,
'catrom': _image.CATROM,
'gaussian': _image.GAUSSIAN,
'bessel': _image.BESSEL,
'mitchell': _image.MITCHELL,
'sinc': _image.SINC,
'lanczos': _image.LANCZOS,
'blackman': _image.BLACKMAN,
}

# the 3 following keys seem to be unused now, keep it for
# backward compatibility just in case.
_interpd = _interpd_
# reverse interp dict
_interpdr = dict([(v, k) for k, v in six.iteritems(_interpd)])

interpnames = list(six.iterkeys(_interpd))
_interpdr = dict([(v, k) for k, v in six.iteritems(_interpd_)])
iterpnames = interpolations_names
# <end unused keys>

def __str__(self):
return "AxesImage(%g,%g;%gx%g)" % tuple(self.axes.bbox.bounds)
Expand Down Expand Up @@ -483,7 +490,7 @@ def set_interpolation(self, s):
if s is None:
s = rcParams['image.interpolation']
s = s.lower()
if s not in self._interpd:
if s not in _interpd_:
raise ValueError('Illegal interpolation string')
self._interpolation = s
self.stale = True
Expand Down Expand Up @@ -617,7 +624,7 @@ def make_image(self, magnification=1.0):
numrows, numcols = im.get_size()
if numrows < 1 or numcols < 1: # out of range
return None
im.set_interpolation(self._interpd[self._interpolation])
im.set_interpolation(_interpd_[self._interpolation])

im.set_resample(self._resample)

Expand Down Expand Up @@ -760,7 +767,7 @@ def make_image(self, magnification=1.0):
im = _image.pcolor(self._Ax, self._Ay, A,
int(height), int(width),
(x0, x0+v_width, y0, y0+v_height),
self._interpd[self._interpolation])
_interpd_[self._interpolation])

fc = self.axes.patch.get_facecolor()
bg = mcolors.colorConverter.to_rgba(fc, 0)
Expand Down Expand Up @@ -1186,7 +1193,7 @@ def make_image(self, renderer, magnification=1.0):
# image input dimensions
im.reset_matrix()

im.set_interpolation(self._interpd[self._interpolation])
im.set_interpolation(_interpd_[self._interpolation])

im.set_resample(self._resample)

Expand Down

0 comments on commit b1b4fb8

Please sign in to comment.