Skip to content

Commit 80b7c57

Browse files
committed
MNT: move creating interal ScalarMappable to where it is used
This make it clearer that we only need this in one of the code paths and avoids creating the un-used ScalarMappable in the png savefig code path.
1 parent d66f959 commit 80b7c57

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/matplotlib/image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,8 +1553,6 @@ def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None,
15531553
else:
15541554
# Don't bother creating an image; this avoids rounding errors on the
15551555
# size when dividing and then multiplying by dpi.
1556-
sm = cm.ScalarMappable(cmap=cmap)
1557-
sm.set_clim(vmin, vmax)
15581556
if origin is None:
15591557
origin = mpl.rcParams["image.origin"]
15601558
if origin == "lower":
@@ -1567,6 +1565,8 @@ def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None,
15671565
# as is, saving a few operations.
15681566
rgba = arr
15691567
else:
1568+
sm = cm.ScalarMappable(cmap=cmap)
1569+
sm.set_clim(vmin, vmax)
15701570
rgba = sm.to_rgba(arr, bytes=True)
15711571
if pil_kwargs is None:
15721572
pil_kwargs = {}

0 commit comments

Comments
 (0)