Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit83f82f2

Browse files
committed
Save a couple of numpy conversions.
1 parentc212f2f commit83f82f2

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

‎lib/matplotlib/backends/backend_agg.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,8 @@ def print_png(self, filename_or_obj, *args,
500500
"""
501501
FigureCanvasAgg.draw(self)
502502
mpl.image.imsave(
503-
filename_or_obj,np.asarray(self.buffer_rgba()),format="png",
504-
origin="upper",dpi=self.figure.dpi,
505-
metadata=metadata,pil_kwargs=pil_kwargs)
503+
filename_or_obj,self.buffer_rgba(),format="png",origin="upper",
504+
dpi=self.figure.dpi,metadata=metadata,pil_kwargs=pil_kwargs)
506505

507506
defprint_to_buffer(self):
508507
FigureCanvasAgg.draw(self)

‎lib/matplotlib/image.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1514,7 +1514,15 @@ def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None,
15141514
origin=mpl.rcParams["image.origin"]
15151515
iforigin=="lower":
15161516
arr=arr[::-1]
1517-
rgba=sm.to_rgba(arr,bytes=True)
1517+
if (isinstance(arr,memoryview)andarr.format=="B"
1518+
andarr.ndim==3andarr.shape[-1]==4):
1519+
# Such an ``arr`` would also be handled fine by sm.to_rgba (after
1520+
# casting with asarray), but it is useful to special-case it
1521+
# because that's what backend_agg passes, and can be in fact used
1522+
# as is, saving a few operations.
1523+
rgba=arr
1524+
else:
1525+
rgba=sm.to_rgba(arr,bytes=True)
15181526
ifpil_kwargsisNone:
15191527
pil_kwargs= {}
15201528
pil_shape= (rgba.shape[1],rgba.shape[0])

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp