8000 Add missing getter/setter methods to keywords of Figure.__init__ as described in #24617 by AlexisMardas · Pull Request #27997 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Add missing getter/setter methods to keywords of Figure.__init__ as described in #24617 #27997

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
120 changes: 120 additions & 0 deletions lib/matplotlib/figure.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -2683,7 +2683,47 @@
# 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)

Check failure on line 2718 in lib/matplotlib/figure.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] reported by reviewdog 🐶 E231 missing whitespace after ',' Raw Output: ./lib/matplotlib/figure.py:2718:38: E231 missing whitespace after ','

def get_layout(self):
# Wrapper class for get_layout_engine
return self.get_layout_engine()

Check failure on line 2723 in lib/matplotlib/figure.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] reported by reviewdog 🐶 W293 blank line contains whitespace Raw Output: ./lib/matplotlib/figure.py:2723:1: W293 blank line contains whitespace


def _repr_html_(self):

Check failure on line 2726 in lib/matplotlib/figure.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] reported by reviewdog 🐶 E303 too many blank lines (3) Raw Output: ./lib/matplotlib/figure.py:2726:5: E303 too many blank lines (3)
# We can't use "isinstance" here, because then we'd end up importing
# webagg unconditionally.
if 'WebAgg' in type(self.canvas).__name__:
Expand Down Expand Up @@ -2885,7 +2925,7 @@
----------
relative : bool
If `True`, then convert from inches to figure relative.
"""

Check failure on line 2928 in lib/matplotlib/figure.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] reported by reviewdog 🐶 E999 IndentationError: expected an indented block Raw Output: ./lib/matplotlib/figure.py:2928:9: E999 IndentationError: expected an indented block
if not isinstance(self.get_layout_engine(), ConstrainedLayoutEngine):
return None, None, None, None
info = self.get_layout_engine().get()
Expand All @@ -2902,6 +2942,54 @@

return w_pad, h_pad, wspace, hspace

def set_subplotparams(self, subplotparams={}):
"""

Check failure on line 2946 in lib/matplotlib/figure.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] reported by reviewdog 🐶 E112 expected an indented block Raw Output: ./lib/matplotlib/figure.py:2946:9: E112 expected an indented block
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
"""
subplotparams_args = ["left", "bottom", "right", "top", "wspace", "hspace"]
if isinstance(subplotparams, dict):
# Filter out the valid keys
kwargs = {key: value for key, value in subplotparams.items() if key in subplotparams_args}

Check failure on line 2968 in lib/matplotlib/figure.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] reported by reviewdog 🐶 E501 line too long (102 > 88 characters) Raw Output: ./lib/matplotlib/figure.py:2968:89: E501 line too long (102 > 88 characters)
self.subplots_adjust(**kwargs)
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()")

Check failure on line 2976 in lib/matplotlib/figure.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] reported by reviewdog 🐶 W293 blank line contains whitespace Raw Output: ./lib/matplotlib/figure.py:2976:1: W293 blank line contains whitespace
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
Expand Down Expand Up @@ -3065,6 +3153,38 @@
The size in pixels can be obtained by multiplying with `Figure.dpi`.
"""
return np.array(self.bbox_inches.p1)

Check failure on line 3156 in lib/matplotlib/figure.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] reported by reviewdog 🐶 W293 blank line contains whitespace Raw Output: ./lib/matplotlib/figure.py:3156:1: W293 blank line contains whitespace
def set_figsize(self, w, h=None, forward=True):
"""
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.

Check failure on line 3173 in lib/matplotlib/figure.py

View workflow job for this annotation

GitHub Actions / flake8

[flake8] reported by reviewdog 🐶 W293 blank line contains whitespace Raw Output: ./lib/matplotlib/figure.py:3173:1: W293 blank line contains whitespace
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)

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."""
Expand Down
Loading
0