8000 Merge pull request #13659 from anntzer/tight · matplotlib/matplotlib@1e40243 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e40243

Browse files
authored
Merge pull request #13659 from anntzer/tight
Clarify behavior of the 'tight' kwarg to autoscale/autoscale_view.
2 parents 5b7ccfe + e6893cf commit 1e40243

File tree

2 files changed

+35
-23
lines changed

2 files changed

+35
-23
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,13 +1644,15 @@ def axis(self, *args, emit=True, **kwargs):
16441644
'equal' Set equal scaling (i.e., make circles circular) by
16451645
changing axis limits.
16461646
'scaled' Set equal scaling (i.e., make circles circular) by
1647-
changing dimensions of the plot box.
1648-
'tight' Set limits just large enough to show all data.
1647+
changing dimensions of the plot box, then disable further
1648+
autoscaling.
1649+
'tight' Set limits just large enough to show all data, then
1650+
disable further autoscaling.
16491651
'auto' Automatic scaling (fill plot box with data).
16501652
'normal' Same as 'auto'; deprecated.
16511653
'image' 'scaled' with axis limits equal to data limits.
16521654
'square' Square plot; similar to 'scaled', but initially forcing
1653-
``xmax-xmin = ymax-ymin``.
1655+
``xmax-xmin == ymax-ymin``.
16541656
======== ==========================================================
16551657
16561658
emit : bool, optional, default *True*
@@ -2366,16 +2368,12 @@ def autoscale(self, enable=True, axis='both', tight=None):
23662368
None leaves the autoscaling state unchanged.
23672369
23682370
axis : {'both', 'x', 'y'}, optional
2369-
which axis to operate on; default is 'both'
2371+
Which axis to operate on; default is 'both'.
23702372
23712373
tight : bool or None, optional
2372-
If True, set view limits to data limits;
2373-
if False, let the locator and margins expand the view limits;
2374-
if None, use tight scaling if the only artist is an image,
2375-
otherwise treat *tight* as False.
2376-
The *tight* setting is retained for future autoscaling
2377-
until it is explicitly changed.
2378-
2374+
If True, first set the margins to zero. Then, this argument is
2375+
forwarded to `autoscale_view` (regardless of its value); see the
2376+
description of its behavior there.
23792377
"""
23802378
if enable is None:
23812379
scalex = True
@@ -2399,17 +2397,31 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True):
23992397
"""
24002398
Autoscale the view limits using the data limits.
24012399
2402-
You can selectively autoscale only a single axis, e.g., the xaxis by
2403-
setting *scaley* to *False*. The autoscaling preserves any
2404-
axis direction reversal that has already been done.
2405-
2406-
If *tight* is *False*, the axis major locator will be used
2407-
to expand the view limits if rcParams['axes.autolimit_mode']
2408-
is 'round_numbers'. Note that any margins that are in effect
2409-
will be applied first, regardless of whether *tight* is
2410-
*True* or *False*. Specifying *tight* as *True* or *False*
2411-
saves the setting as a private attribute of the Axes; specifying
2412-
it as *None* (the default) applies the previously saved value.
2400+
Parameters
2401+
----------
2402+
tight : bool or None
2403+
If *True*, only expand the axis limits using the margins. Note
2404+
that unlike for `autoscale`, ``tight=True`` does *not* set the
2405+
margins to zero.
2406+
2407+
If *False* and :rc:`axes.autolimit_mode` is 'round_numbers', then
2408+
after expansion by the margins, further expand the axis limits
2409+
using the axis major locator.
2410+
2411+
If None (the default), reuse the value set in the previous call to
2412+
`autoscale_view` (the initial value is False, but the default style
2413+
sets :rc:`axes.autolimit_mode` to 'data', in which case this
2414+
behaves like True).
2415+
2416+
scalex : bool
2417+
Whether to autoscale the x axis (default is True).
2418+
2419+
scaley : bool
2420+
Whether to autoscale the x axis (default is True).
2421+
2422+
Notes
2423+
-----
2424+
The autoscaling preserves any preexisting axis direction reversal.
24132425
24142426
The data limits are not updated automatically when artist data are
24152427
changed after the artist has been added to an Axes instance. In that

matplotlibrc.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@
333333
## as opposed to the rest of this file.
334334
#axes.autolimit_mode : data ## How to scale axes limits to the data.
335335
## Use "data" to use data limits, plus some margin
336-
## Use "round_number" move to the nearest "round" number
336+
## Use "round_numbers" move to the nearest "round" number
337337
#axes.xmargin : .05 ## x margin. See `axes.Axes.margins`
338338
#axes.ymargin : .05 ## y margin See `axes.Axes.margins`
339339
#polaraxes.grid : True ## display grid on polar axes

0 commit comments

Comments
 (0)
0