10000 Clarify behavior of the 'tight' kwarg to autoscale/autoscale_view. by anntzer · Pull Request #13659 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Clarify behavior of the 'tight' kwarg to autoscale/autoscale_view. #13659

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

Merged
merged 1 commit into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
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
56 changes: 34 additions & 22 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1617,13 +1617,15 @@ def axis(self, *args, **kwargs):
'equal' Set equal scaling (i.e., make circles circular) by
changing axis limits.
'scaled' Set equal scaling (i.e., make circles circular) by
changing dimensions of the plot box.
'tight' Set limits just large enough to show all data.
changing dimensions of the plot box, then disable further
autoscaling.
'tight' Set limits just large enough to show all data, then
disable further autoscaling.
'auto' Automatic scaling (fill plot box with data).
'normal' Same as 'auto'; deprecated.
'image' 'scaled' with axis limits equal to data limits.
'square' Square plot; similar to 'scaled', but initially forcing
``xmax-xmin = ymax-ymin``.
``xmax-xmin == ymax-ymin``.
======== ==========================================================

emit : bool, optional, default *True*
Expand Down Expand Up @@ -2348,16 +2350,12 @@ def autoscale(self, enable=True, axis='both', tight=None):
None leaves the autoscaling state unchanged.

axis : {'both', 'x', 'y'}, optional
which axis to operate on; default is 'both'
Which axis to operate on; default is 'both'.

tight : bool or None, optional
If True, set view limits to data limits;
if False, let the locator and margins expand the view limits;
if None, use tight scaling if the only artist is an image,
otherwise treat *tight* as False.
The *tight* setting is retained for future autoscaling
until it is explicitly changed.

If True, first set the margins to zero. Then, this argument is
forwarded to `autoscale_view` (regardless of its value); see the
description of its behavior there.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

(It's complicated enough that I decided against duplicating the text. Note that the old version is wrong since mpl2.0.)

"""
if enable is None:
scalex = True
Expand All @@ -2381,17 +2379,31 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True):
"""
Autoscale the view limits using the data limits.

You can selectively autoscale only a single axis, e.g., the xaxis by
setting *scaley* to *False*. The autoscaling preserves any
axis direction reversal that has already been done.

If *tight* is *False*, the axis major locator will be used
to expand the view limits if rcParams['axes.autolimit_mode']
is 'round_numbers'. Note that any margins that are in effect
will be applied first, regardless of whether *tight* is
*True* or *False*. Specifying *tight* as *True* or *False*
saves the setting as a private attribute of the Axes; specifying
it as *None* (the default) applies the previously saved value.
Parameters
----------
tight : bool or None
If *True*, only expand the axis limits using the margins. Note
that unlike for `autoscale`, ``tight=True`` does *not* set the
margins to zero.

If *False* and :rc:`axes.autolimit_mode` is 'round_numbers', then
after expansion by the margins, further expand the axis limits
using the axis major locator.

If None (the default), reuse the value set in the previous call to
`autoscale_view` (the initial value is False, but the default style
sets :rc:`axes.autolimit_mode` to 'data', in which case this
behaves like True).

scalex : bool
Whether to autoscale the x axis (default is True).

scaley : bool
Whether to autoscale the x axis (default is True).

Notes
-----
The autoscaling preserves any preexisting axis direction reversal.

The data limits are not updated automatically when artist data are
changed after the artist has been added to an Axes instance. In that
Expand Down
2 changes: 1 addition & 1 deletion matplotlibrc.template
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@
## as opposed to the rest of this file.
#axes.autolimit_mode : data ## How to scale axes limits to the data.
## Use "data" to use data limits, plus some margin
## Use "round_number" move to the nearest "round" number
## Use "round_numbers" move to the nearest "round" number
#axes.xmargin : .05 ## x margin. See `axes.Axes.margins`
#axes.ymargin : .05 ## y margin See `axes.Axes.margins`
#polaraxes.grid : True ## display grid on polar axes
Expand Down
0