|
34 | 34 | from matplotlib.transforms import BboxBase, Bbox, IdentityTransform
|
35 | 35 | import matplotlib.transforms as mtransforms
|
36 | 36 |
|
| 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 | + |
37 | 62 |
|
38 | 63 | class _AxesImageBase(martist.Artist, cm.ScalarMappable):
|
39 | 64 | 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 |
| - } |
61 | 65 |
|
| 66 | + # the 3 following keys seem to be unused now, keep it for |
| 67 | + # backward compatibility just in case. |
| 68 | + _interpd = _interpd_ |
62 | 69 | # 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> |
66 | 73 |
|
67 | 74 | def __str__(self):
|
68 | 75 | return "AxesImage(%g,%g;%gx%g)" % tuple(self.axes.bbox.bounds)
|
@@ -483,7 +490,7 @@ def set_interpolation(self, s):
|
483 | 490 | if s is None:
|
484 | 491 | s = rcParams['image.interpolation']
|
485 | 492 | s = s.lower()
|
486 |
| - if s not in self._interpd: |
| 493 | + if s not in _interpd_: |
487 | 494 | raise ValueError('Illegal interpolation string')
|
488 | 495 | self._interpolation = s
|
489 | 496 | self.stale = True
|
@@ -617,7 +624,7 @@ def make_image(self, magnification=1.0):
|
617 | 624 | numrows, numcols = im.get_size()
|
618 | 625 | if numrows < 1 or numcols < 1: # out of range
|
619 | 626 | return None
|
620 |
| - im.set_interpolation(self._interpd[self._interpolation]) |
| 627 | + im.set_interpolation(_interpd_[self._interpolation]) |
621 | 628 |
|
622 | 629 | im.set_resample(self._resample)
|
623 | 630 |
|
@@ -760,7 +767,7 @@ def make_image(self, magnification=1.0):
|
760 | 767 | im = _image.pcolor(self._Ax, self._Ay, A,
|
761 | 768 | int(height), int(width),
|
762 | 769 | (x0, x0+v_width, y0, y0+v_height),
|
763 |
| - self._interpd[self._interpolation]) |
| 770 | + _interpd_[self._interpolation]) |
764 | 771 |
|
765 | 772 | fc = self.axes.patch.get_facecolor()
|
766 | 773 | bg = mcolors.colorConverter.to_rgba(fc, 0)
|
@@ -1186,7 +1193,7 @@ def make_image(self, renderer, magnification=1.0):
|
1186 | 1193 | # image input dimensions
|
1187 | 1194 | im.reset_matrix()
|
1188 | 1195 |
|
1189 |
| - im.set_interpolation(self._interpd[self._interpolation]) |
| 1196 | + im.set_interpolation(_interpd_[self._interpolation]) |
1190 | 1197 |
|
1191 | 1198 | im.set_resample(self._resample)
|
1192 | 1199 |
|
|
0 commit comments