Skip to content
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
19 changes: 19 additions & 0 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,25 @@ def figure(num=None, # autoincrement if None, else integer from 1-N
clear : bool, default: False
If True and the figure already exists, then it is cleared.

tight_layout : bool or dict, default: :rc:`figure.autolayout`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this doesn't need to be listed explicitly here? It's a normal Figure kwarg anyways, so documented there; if anything we may rather want to promote the use of constrained_layout?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, nothing really has to be listed explicitly here. All the arguments here but one are indeed duplicates of figure.Figure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with tight_layout here, but should also add constrained_layout (can be a diff PR). The sphinx link below needs to be fixed (leading dot?, I really find sphinx documentation to be hard to make valid cross-references for).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: sphinx references: any reference to something not in the current module needs to be prefixed by a dot. Possibly with the module name in front to disambiguate further (e.g. between .Axes.plot and .pyplot.plot, otherwise sphinx reasonably complains that it doesn't know which one to use), but not necessary if there is no ambiguity (e.g. .Figure). What gets printed in the rendered html is what you put between the backquotes, minus the leading dot, unless you add a tilde in front of it, in which case all the context is stripped so e.g. ~.Axes.plot and ~.pyplot.plot both get rendered as plot.
(This is made slightly more complicated by the fact that often we have docstrings that are originally defined in one module but end up also in an object defined in another module (via inheritance); sphinx is not able to follow that and will complain if the inherited docstring "wanted" to refer to objects in the first module without using a leading dot.)
Also anything referring to something not in matplotlib at all (i.e. numpy, etc.) needs to be fully qualified.

If ``False`` use *subplotpars*. If ``True`` adjust subplot
parameters using `.tight_layout` with default padding.
When providing a dict containing the keys ``pad``, ``w_pad``,
``h_pad``, and ``rect``, the default `.tight_layout` paddings
will be overridden.

constrained_layout : bool, default: :rc:`figure.constrained_layout.use`
If ``True`` use constrained layout to adjust positioning of plot
elements. Like ``tight_layout``, but designed to be more
flexible. See
:doc:`/tutorials/intermediate/constrainedlayout_guide`
for examples. (Note: does not work with `add_subplot` or
`~.pyplot.subplot2grid`.)


**kwargs : optional
See `~.matplotlib.figure.Figure` for other possible arguments.

Returns
-------
figure : `~matplotlib.figure.Figure`
Expand Down