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

Skip to content

Commit 4c5da38

Browse files
committed
Rename a confusing variable.
As noted in #19059, there is both a `buff` and `buf` in this function. The latter is a PNG file, so rename it to `png`.
1 parent b556e62 commit 4c5da38

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lib/matplotlib/backends/backend_webagg_core.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,15 @@ def get_diff_image(self):
196196
diff = buff != self._last_buff
197197
output = np.where(diff, buff, 0)
198198

199-
buf = BytesIO()
200-
data = output.view(dtype=np.uint8).reshape((*output.shape, 4))
201-
Image.fromarray(data).save(buf, format="png")
202-
# store the current buffer so we can compute the next diff
199+
# Store the current buffer so we can compute the next diff.
203200
np.copyto(self._last_buff, buff)
204201
self._force_full = False
205202
self._png_is_old = False
206-
return buf.getvalue()
203+
204+
data = output.view(dtype=np.uint8).reshape((*output.shape, 4))
205+
with BytesIO() as png:
206+
Image.fromarray(data).save(png, format="png")
207+
return png.getvalue()
207208

208209
def get_renderer(self, cleared=None):
209210
# Mirrors super.get_renderer, but caches the old one so that we can do

0 commit comments

Comments
 (0)