8000 Shorten Figure.set_size_inches. · matplotlib/matplotlib@431bd8e · GitHub
[go: up one dir, main page]

Skip to content

Commit 431bd8e

Browse files
committed
Shorten Figure.set_size_inches.
1 parent 0f0ef9c commit 431bd8e

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

lib/matplotlib/figure.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -890,26 +890,19 @@ def set_size_inches(self, w, h=None, forward=True):
890890
--------
891891
matplotlib.Figure.get_size_inches
892892
"""
893-
894-
# the width and height have been passed in as a tuple to the first
895-
# argument, so unpack them
896-
if h is None:
893+
if h is None: # Got called with a single pair as argument.
897894
w, h = w
898-
size = w, h
899-
if not np.isfinite(size).all() or (np.array(size) <= 0).any():
895+
size = np.array([w, h])
896+
if not np.isfinite(size).all() or (size <= 0).any():
900897
raise ValueError(f'figure size must be positive finite not {size}')
901-
self.bbox_inches.p1 = w, h
902-
898+
self.bbox_inches.p1 = size
903899
if forward:
904900
canvas = getattr(self, 'canvas')
905901
if canvas is not None:
906-
ratio = getattr(self.canvas, '_dpi_ratio', 1)
907-
dpival = self.dpi / ratio
908-
canvasw = w * dpival
909-
canvash = h * dpival
910-
manager = getattr(self.canvas, 'manager', None)
902+
dpi_ratio = getattr(canvas, '_dpi_ratio', 1)
903+
manager = getattr(canvas, 'manager', None)
911904
if manager is not None:
912-
manager.resize(int(canvasw), int(canvash))
905+
manager.resize(*(size * self.dpi / dpi_ratio).astype(int))
913906
self.stale = True
914907

915908
def get_size_inches(self):

0 commit comments

Comments
 (0)
0