Skip to content

NF - Added set_size_cm and get_size_cm for figures #5104

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

Closed
wants to merge 5 commits into from
Closed
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
8 changes: 7 additions & 1 deletion lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,9 @@ def set_size_inches(self, w, h=None, forward=False):
manager.resize(int(canvasw), int(canvash))
self.stale = True

def set_size_cm(self, w, h=None, **kwargs):
return self.set_size_inches(w*(1/2.54), h*(1/2.54) if h is not None else None, **kwargs)

def get_size_inches(self):
"""
Returns the current size of the figure in inches (1in == 2.54cm)
Expand All @@ -725,6 +728,9 @@ def get_size_inches(self):
"""
return np.array(self.bbox_inches.p1)

def get_size_cm(self):
return np.array(self.bbox_inches.p1)*2.54

def get_edgecolor(self):
'Get the edge color of the Figure rectangle'
return self.patch.get_edgecolor()
Expand Down Expand Up @@ -1792,4 +1798,4 @@ def figaspect(arg):
newsize = np.clip(newsize, figsize_min, figsize_max)
return newsize

docstring.interpd.update(Figure=martist.kwdoc(Figure))
docstring.interpd.update(Figure=martist.kwdoc(Figure))