Skip to content
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

Expose interpolation short names at module level. #4718

Merged
merged 7 commits into from Jul 22, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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