8000 Shorten Figure.set_size_inches. by anntzer · Pull Request #13886 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Shorten Figure.set_size_inches. #13886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,26 +890,19 @@ def set_size_inches(self, w, h=None, forward=True):
--------
matplotlib.Figure.get_size_inches
"""

# the width and height have been passed in as a tuple to the first
# argument, so unpack them
if h is None:
if h is None: # Got called with a single pair as argument.
w, h = w
size = w, h
if not np.isfinite(size).all() or (np.array(size) <= 0).any():
size = np.array([w, h])
if not np.isfinite(size).all() or (size <= 0).any():
raise ValueError(f'figure size must be positive finite not {size}')
self.bbox_inches.p1 = w, h

self.bbox_inches.p1 = size
if forward:
canvas = getattr(self, 'canvas')
if canvas is not None:
ratio = getattr(self.canvas, '_dpi_ratio', 1)
dpival = self.dpi / ratio
canvasw = w * dpival
canvash = h * dpival
manager = getattr(self.canvas, 'manager', None)
dpi_ratio = getattr(canvas, '_dpi_ratio', 1)
manager = getattr(canvas, 'manager', None)
if manager is not None:
manager.resize(int(canvasw), int(canvash))
manager.resize(*(size * self.dpi / dpi_ratio).astype(int))
self.stale = True

def get_size_inches(self):
Expand Down
0