Skip to content

Commit fc97fc8

Browse files
committed
PcolorImage: use local cache instead of the ScalarMappable.update_dict
svn path=/trunk/matplotlib/; revision=8949
1 parent 93c041b commit fc97fc8

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

lib/matplotlib/cm.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def revcmap(data):
4343
def _reverse_cmap_spec(spec):
4444
"""Reverses cmap specification *spec*, can handle both dict and tuple
4545
type specs."""
46-
46+
4747
if 'red' in spec:
4848
return revcmap(spec)
4949
else:
@@ -53,9 +53,9 @@ def _reverse_cmap_spec(spec):
5353
return revspec
5454

5555
def _generate_cmap(name, lutsize):
56-
"""Generates the requested cmap from it's name *name*. The lut size is
56+
"""Generates the requested cmap from it's name *name*. The lut size is
5757
*lutsize*."""
58-
58+
5959
spec = datad[name]
6060

6161
# Generate the colormap object.

lib/matplotlib/image.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def __init__(self, ax,
9797

9898
self._imcache = None
9999

100-
# this is an expetimental attribute, if True, unsampled image
100+
# this is an experimental attribute, if True, unsampled image
101101
# will be drawn using the affine transform that are
102102
# appropriately skewed so that the given postition
103103
# corresponds to the actual position in the coordinate. -JJL
@@ -797,6 +797,9 @@ def __init__(self, ax,
797797
cm.ScalarMappable.__init__(self, norm, cmap)
798798
self.axes = ax
799799
self._rgbacache = None
800+
# There is little point in caching the image itself because
801+
# it needs to be remade if the bbox or viewlim change,
802+
# so caching does help with zoom/pan/resize.
800803
self.update(kwargs)
801804
self.set_data(x, y, A)
802805

@@ -811,7 +814,7 @@ def make_image(self, magnification=1.0):
811814
height = (round(t) + 0.5) - (round(b) - 0.5)
812815
width = width * magnification
813816
height = height * magnification
814-
if self.check_update('array'):
817+
if self._rgbacache is None:
815818
A = self.to_rgba(self._A, alpha=self._alpha, bytes=True)
816819
self._rgbacache = A
817820
if self._A.ndim == 2:
@@ -827,9 +830,14 @@ def make_image(self, magnification=1.0):
827830
im.is_grayscale = self.is_grayscale
828831
return im
829832

833+
def changed(self):
834+
self._rgbacache = None
835+
cm.ScalarMappable.changed(self)
836+
830837
@allow_rasterization
831838
def draw(self, renderer, *args, **kwargs):
832-
if not self.get_visible(): return
839+
if not self.get_visible():
840+
return
833841
im = self.make_image(renderer.get_image_magnification())
834842
gc = renderer.new_gc()
835843
gc.set_clip_rectangle(self.axes.bbox.frozen())
@@ -871,7 +879,7 @@ def set_data(self, x, y, A):
871879
self._A = A
872880
self._Ax = x
873881
self._Ay = y
874-
self.update_dict['array'] = True
882+
self._rgbacache = None
875883

876884
def set_array(self, *args):
877885
raise NotImplementedError('Method not supported')

0 commit comments

Comments
 (0)