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

Skip to content

Commit b1b4fb8

Browse files
committed
Merge pull request matplotlib#4718 from Carreau/global-interpolation
Expose interpolation short names at module level.
2 parents 1097e3f + 743876c commit b1b4fb8

File tree

1 file changed

+35
-28
lines changed

1 file changed

+35
-28
lines changed

lib/matplotlib/image.py

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,35 +34,42 @@
3434
from matplotlib.transforms import BboxBase, Bbox, IdentityTransform
3535
import matplotlib.transforms as mtransforms
3636

37+
# map interpolation strings to module constants
38+
_interpd_ = {
39+
'none': _image.NEAREST, # fall back to nearest when not supported
40+
'nearest': _image.NEAREST,
41+
'bilinear': _image.BILINEAR,
42+
'bicubic': _image.BICUBIC,
43+
'spline16': _image.SPLINE16,
44+
'spline36': _image.SPLINE36,
45+
'hanning': _image.HANNING,
46+
'hamming': _image.HAMMING,
47+
'hermite': _image.HERMITE,
48+
'kaiser': _image.KAISER,
49+
'quadric': _image.QUADRIC,
50+
'catrom': _image.CATROM,
51+
'gaussian': _image.GAUSSIAN,
52+
'bessel': _image.BESSEL,
53+
'mitchell': _image.MITCHELL,
54+
'sinc': _image.SINC,
55+
'lanczos': _image.LANCZOS,
56+
'blackman': _image.BLACKMAN,
57+
}
58+
59+
60+
interpolations_names = set(six.iterkeys(_interpd_))
61+
3762

3863
class _AxesImageBase(martist.Artist, cm.ScalarMappable):
3964
zorder = 0
40-
# map interpolation strings to module constants
41-
_interpd = {
42-
'none': _image.NEAREST, # fall back to nearest when not supported
43-
'nearest': _image.NEAREST,
44-
'bilinear': _image.BILINEAR,
45-
'bicubic': _image.BICUBIC,
46-
'spline16': _image.SPLINE16,
47-
'spline36': _image.SPLINE36,
48-
'hanning': _image.HANNING,
49-
'hamming': _image.HAMMING,
50-
'hermite': _image.HERMITE,
51-
'kaiser': _image.KAISER,
52-
'quadric': _image.QUADRIC,
53-
'catrom': _image.CATROM,
54-
'gaussian': _image.GAUSSIAN,
55-
'bessel': _image.BESSEL,
56-
'mitchell': _image.MITCHELL,
57-
'sinc': _image.SINC,
58-
'lanczos': _image.LANCZOS,
59-
'blackman': _image.BLACKMAN,
60-
}
6165

66+
# the 3 following keys seem to be unused now, keep it for
67+
# backward compatibility just in case.
68+
_interpd = _interpd_
6269
# reverse interp dict
63-
_interpdr = dict([(v, k) for k, v in six.iteritems(_interpd)])
64-
65-
interpnames = list(six.iterkeys(_interpd))
70+
_interpdr = dict([(v, k) for k, v in six.iteritems(_interpd_)])
71+
iterpnames = interpolations_names
72+
# <end unused keys>
6673

6774
def __str__(self):
6875
return "AxesImage(%g,%g;%gx%g)" % tuple(self.axes.bbox.bounds)
@@ -483,7 +490,7 @@ def set_interpolation(self, s):
483490
if s is None:
484491
s = rcParams['image.interpolation']
485492
s = s.lower()
486-
if s not in self._interpd:
493+
if s not in _interpd_:
487494
raise ValueError('Illegal interpolation string')
488495
self._interpolation = s
489496
self.stale = True
@@ -617,7 +624,7 @@ def make_image(self, magnification=1.0):
617624
numrows, numcols = im.get_size()
618625
if numrows < 1 or numcols < 1: # out of range
619626
return None
620-
im.set_interpolation(self._interpd[self._interpolation])
627+
im.set_interpolation(_interpd_[self._interpolation])
621628

622629
im.set_resample(self._resample)
623630

@@ -760,7 +767,7 @@ def make_image(self, magnification=1.0):
760767
im = _image.pcolor(self._Ax, self._Ay, A,
761768
int(height), int(width),
762769
(x0, x0+v_width, y0, y0+v_height),
763-
self._interpd[self._interpolation])
770+
_interpd_[self._interpolation])
764771

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

1189-
im.set_interpolation(self._interpd[self._interpolation])
1196+
im.set_interpolation(_interpd_[self._interpolation])
11901197

11911198
im.set_resample(self._resample)
11921199

0 commit comments

Comments
 (0)