10000 Merge pull request #21910 from anntzer/rgbacache · matplotlib/matplotlib@e9958e1 · GitHub
[go: up one dir, main page]

Skip to content

Commit e9958e1

Browse files
authored
Merge pull request #21910 from anntzer/rgbacache
Fold _rgbacache into _imcache.
2 parents 6e15597 + 84cc167 commit e9958e1

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

lib/matplotlib/image.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,8 @@ def __init__(self, ax,
260260
self.update(kwargs)
261261

262262
def __getstate__(self):
263-
state = super().__getstate__()
264-
# We can't pickle the C Image cached object.
265-
state['_imcache'] = None
266-
return state
263+
# Save some space on the pickle by not saving the cache.
264+
return {**super().__getstate__(), "_imcache": None}
267265

268266
def get_size(self):
269267
"""Return the size of the image as tuple (numrows, numcols)."""
@@ -304,7 +302,6 @@ def changed(self):
304302
Call this whenever the mappable is changed so observers can update.
305303
"""
306304
self._imcache = None
307-
self._rgbacache = None
308305
cm.ScalarMappable.changed(self)
309306

310307
def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
@@ -710,7 +707,6 @@ def set_data(self, A):
710707
self._A = self._A.astype(np.uint8)
711708

712709
self._imcache = None
713-
self._rgbacache = None
714710
self.stale = True
715711

716712
def set_array(self, A):
@@ -1214,10 +1210,10 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
12141210
if unsampled:
12151211
raise ValueError('unsampled not supported on PColorImage')
12161212

1217-
if self._rgbacache is None:
1213+
if self._imcache is None:
12181214
A = self.to_rgba(self._A, bytes=True)
1219< 951A code class="diff-text syntax-highlighted-line deletion">-
self._rgbacache = np.pad(A, [(1, 1), (1, 1), (0, 0)], "constant")
1220-
padded_A = self._rgbacache
1215+
self._imcache = np.pad(A, [(1, 1), (1, 1), (0, 0)], "constant")
1216+
padded_A = self._imcache
12211217
bg = mcolors.to_rgba(self.axes.patch.get_facecolor(), 0)
12221218
bg = (np.array(bg) * 255).astype(np.uint8)
12231219
if (padded_A[0, 0] != bg).all():
@@ -1294,7 +1290,7 @@ def set_data(self, x, y, A):
12941290
self._A = A
12951291
self._Ax = x
12961292
self._Ay = y
1297-
self._rgbacache = None
1293+
self._imcache = None
12981294
self.stale = True
12991295

13001296
def set_array(self, *args):

0 commit comments

Comments
 (0)
0