From 76f9443e1e40ff4eebad382d7a40bfb97259117c Mon Sep 17 00:00:00 2001 From: theodoraiakovaki Date: Thu, 28 Mar 2024 14:44:37 +0200 Subject: [PATCH 1/5] Refactor set_size_inches method to set_figsize for clarity and consistency --- lib/matplotlib/figure.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 087c193d48c3..beea7a490ffe 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -3012,6 +3012,38 @@ def get_size_inches(self): The size in pixels can be obtained by multiplying with `Figure.dpi`. """ return np.array(self.bbox_inches.p1) + + def set_figsize(self, w, h=None): + """ + Set the figure size in inches. + Call signatures:: + fig.set_size_inches(w, h) # OR + fig.set_size_inches((w, h)) + Parameters + ---------- + w : (float, float) or float + Width and height in inches (if height not specified as a separate + argument) or width. + h : float + Height in inches. + forward : bool, default: True + If ``True``, the canvas size is automatically updated, e.g., + you can resize the figure window from the shell. + + See Also + -------- + matplotlib.figure.Figure.get_size_inches + matplotlib.figure.Figure.set_figwidth + matplotlib.figure.Figure.set_figheight + Notes + ----- + To transform from pixels to inches divide by `Figure.dpi`. + """ + self.set_size_inches(w, h, forward=True) + + def get_figsize(self): + """Return the figure size in inches.""" + return self.get_size_inches() def get_figwidth(self): """Return the figure width in inches.""" From 682914cbe72b3a807211c1d43fda3bed2aa243ae Mon Sep 17 00:00:00 2001 From: AlexisMardas Date: Fri, 29 Mar 2024 02:35:18 +0200 Subject: [PATCH 2/5] Create setter/getter for layout, to improve name consistency --- lib/matplotlib/figure.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index beea7a490ffe..c47f637194ff 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -2630,6 +2630,46 @@ def get_layout_engine(self): # to the figure in the right context, but then IPython doesn't # use it, for some reason. + def set_layout(self, layout=None, **kwargs): + """ + Wrapper method for set_layout_engine, used to provide consistency between the + variable's name and it's setter. + + Parameters + ---------- + layout : {'constrained', 'compressed', 'tight', 'none', `.LayoutEngine`, None} + + - 'constrained' will use `~.ConstrainedLayoutEngine` + - 'compressed' will also use `~.ConstrainedLayoutEngine`, but with + a correction that attempts to make a good layout for fixed-aspect + ratio Axes. + - 'tight' uses `~.TightLayoutEngine` + - 'none' removes layout engine. + + If a `.LayoutEngine` instance, that instance will be used. + + If `None`, the behavior is controlled by :rc:`figure.autolayout` + (which if `True` behaves as if 'tight' was passed) and + :rc:`figure.constrained_layout.use` (which if `True` behaves as if + 'constrained' was passed). If both are `True`, + :rc:`figure.autolayout` takes priority. + + Users and libraries can define their own layout engines and pass + the instance directly as well. + + **kwargs + The keyword arguments are passed to the layout engine to set things + like padding and margin sizes. Only used if *layout* is a string. + + """ + self.set_layout_engine(layout,**kwargs) + + def get_layout(self): + # Wrapper class for get_layout_engine + return self.get_layout_engine() + + + def _repr_html_(self): # We can't use "isinstance" here, because then we'd end up importing # webagg unconditionally. From 6488938be7387748ce5e25e976570446cdc588c4 Mon Sep 17 00:00:00 2001 From: theodoraiakovaki Date: Sat, 30 Mar 2024 11:26:17 +0200 Subject: [PATCH 3/5] Fix arguments for figsize method --- lib/matplotlib/figure.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index c47f637194ff..2a10c1e81370 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -3053,7 +3053,7 @@ def get_size_inches(self): """ return np.array(self.bbox_inches.p1) - def set_figsize(self, w, h=None): + def set_figsize(self, w, h=None, forward=True): """ Set the figure size in inches. Call signatures:: @@ -3079,7 +3079,7 @@ def set_figsize(self, w, h=None): ----- To transform from pixels to inches divide by `Figure.dpi`. """ - self.set_size_inches(w, h, forward=True) + self.set_size_inches(w, h, forward) def get_figsize(self): """Return the figure size in inches.""" From e10a31b50cd1fbe5b7b5b944e2e797669327a67b Mon Sep 17 00:00:00 2001 From: Andriana Lazana <116111314+andrianalazana@users.noreply.github.com> Date: Sat, 30 Mar 2024 14:10:29 +0200 Subject: [PATCH 4/5] Update figure.py with set_subplotparams and get_subplotparams --- lib/matplotlib/figure.py | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 2a10c1e81370..51384e4402e3 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -2889,6 +2889,54 @@ def get_constrained_layout_pads(self, relative=False): return w_pad, h_pad, wspace, hspace + def set_subplotparams(self, subplotparams={}): + """ + Set the subplot layout parameters. + Accepts either a `.SubplotParams` object, from which the relevant + parameters are copied, or a dictionary of subplot layout parameters. + If a dictionary is provided, this function is a convenience wrapper for + `matplotlib.figure.Figure.subplots_adjust` + Parameters + ---------- + subplotparams : `~matplotlib.figure.SubplotParams` or dict with keys \ + "left", "bottom", "right", 'top", "wspace", "hspace"] , optional + SubplotParams object to copy new subplot parameters from, or a dict + of SubplotParams constructor arguments. + By default, an empty dictionary is passed, which maintains the + current state of the figure's `.SubplotParams` + See Also + -------- + matplotlib.figure.Figure.subplots_adjust + matplotlib.figure.Figure.get_subplotparams + """ + valid_keys = ["left", "bottom", "right", "top", "wspace", "hspace"] + if isinstance(subplotparams, dict): + # Filter out the valid keys + valid_params = {key: value for key, value in subplotparams.items() if key in valid_keys} + self.subplots_adjust(**valid_params) + elif isinstance(subplotparams, SubplotParams): + self.subplots_adjust(**subplotparams.__dict__) + else: + raise TypeError( + "subplotparams must be a dictionary of keyword-argument pairs or" + " an instance of SubplotParams()") + + if not subplotparams: + self.set_subplotparams(self.get_subplotparams()) + + def get_subplotparams(self): + """ + Return the `.SubplotParams` object associated with the Figure. + Returns + ------- + `.SubplotParams` + See Also + -------- + matplotlib.figure.Figure.subplots_adjust + matplotlib.figure.Figure.get_subplotparams + """ + return self.subplotpars + def set_canvas(self, canvas): """ Set the canvas that contains the figure From 0bd0b2b1c1773d6e5818f87d154ae8a98edb714f Mon Sep 17 00:00:00 2001 From: Andriana Lazana <116111314+andrianalazana@users.noreply.github.com> Date: Sun, 31 Mar 2024 17:29:52 +0300 Subject: [PATCH 5/5] Update figure.py --- lib/matplotlib/figure.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 51384e4402e3..df3e3c01d865 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -2909,11 +2909,11 @@ def set_subplotparams(self, subplotparams={}): matplotlib.figure.Figure.subplots_adjust matplotlib.figure.Figure.get_subplotparams """ - valid_keys = ["left", "bottom", "right", "top", "wspace", "hspace"] + subplotparams_args = ["left", "bottom", "right", "top", "wspace", "hspace"] if isinstance(subplotparams, dict): # Filter out the valid keys - valid_params = {key: value for key, value in subplotparams.items() if key in valid_keys} - self.subplots_adjust(**valid_params) + kwargs = {key: value for key, value in subplotparams.items() if key in subplotparams_args} + self.subplots_adjust(**kwargs) elif isinstance(subplotparams, SubplotParams): self.subplots_adjust(**subplotparams.__dict__) else: pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy