diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index fccf69e6e628..b15b489a2f6e 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -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) @@ -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() @@ -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)) \ No newline at end of file