Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e6893cf

Browse filesBrowse files
committed
Clarify behavior of the 'tight' kwarg to autoscale/autoscale_view.
The 'tight' kwarg behaves subtly differently in autoscale and in autoscale_view (in the former, it additionally sets the margins to zero). In autoscale_view, the default of tight=True actually has no effect in the default style, which disables it via an rcParam (which, by the way, is documented with a typo in matplotlibrc.template). Try to clarify these less-than-obvious behaviors.
1 parent adda7cc commit e6893cf
Copy full SHA for e6893cf

File tree

Expand file treeCollapse file tree

2 files changed

+35
-23
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+35
-23
lines changed

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+34-22Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,13 +1617,15 @@ def axis(self, *args, **kwargs):
16171617
'equal' Set equal scaling (i.e., make circles circular) by
16181618
changing axis limits.
16191619
'scaled' Set equal scaling (i.e., make circles circular) by
1620-
changing dimensions of the plot box.
1621-
'tight' Set limits just large enough to show all data.
1620+
changing dimensions of the plot box, then disable further
1621+
autoscaling.
1622+
'tight' Set limits just large enough to show all data, then
1623+
disable further autoscaling.
16221624
'auto' Automatic scaling (fill plot box with data).
16231625
'normal' Same as 'auto'; deprecated.
16241626
'image' 'scaled' with axis limits equal to data limits.
16251627
'square' Square plot; similar to 'scaled', but initially forcing
1626-
``xmax-xmin = ymax-ymin``.
1628+
``xmax-xmin == ymax-ymin``.
16271629
======== ==========================================================
16281630
16291631
emit : bool, optional, default *True*
@@ -2348,16 +2350,12 @@ def autoscale(self, enable=True, axis='both', tight=None):
23482350
None leaves the autoscaling state unchanged.
23492351
23502352
axis : {'both', 'x', 'y'}, optional
2351-
which axis to operate on; default is 'both'
2353+
Which axis to operate on; default is 'both'.
23522354
23532355
tight : bool or None, optional
2354-
If True, set view limits to data limits;
2355-
if False, let the locator and margins expand the view limits;
2356-
if None, use tight scaling if the only artist is an image,
2357-
otherwise treat *tight* as False.
2358-
The *tight* setting is retained for future autoscaling
2359-
until it is explicitly changed.
2360-
2356+
If True, first set the margins to zero. Then, this argument is
2357+
forwarded to `autoscale_view` (regardless of its value); see the
2358+
description of its behavior there.
23612359
"""
23622360
if enable is None:
23632361
scalex = True
@@ -2381,17 +2379,31 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True):
23812379
"""
23822380
Autoscale the view limits using the data limits.
23832381
2384-
You can selectively autoscale only a single axis, e.g., the xaxis by
2385-
setting *scaley* to *False*. The autoscaling preserves any
2386-
axis direction reversal that has already been done.
2387-
2388-
If *tight* is *False*, the axis major locator will be used
2389-
to expand the view limits if rcParams['axes.autolimit_mode']
2390-
is 'round_numbers'. Note that any margins that are in effect
2391-
will be applied first, regardless of whether *tight* is
2392-
*True* or *False*. Specifying *tight* as *True* or *False*
2393-
saves the setting as a private attribute of the Axes; specifying
2394-
it as *None* (the default) applies the previously saved value.
2382+
Parameters
2383+
----------
2384+
tight : bool or None
2385+
If *True*, only expand the axis limits using the margins. Note
2386+
that unlike for `autoscale`, ``tight=True`` does *not* set the
2387+
margins to zero.
2388+
2389+
If *False* and :rc:`axes.autolimit_mode` is 'round_numbers', then
2390+
after expansion by the margins, further expand the axis limits
2391+
using the axis major locator.
2392+
2393+
If None (the default), reuse the value set in the previous call to
2394+
`autoscale_view` (the initial value is False, but the default style
2395+
sets :rc:`axes.autolimit_mode` to 'data', in which case this
2396+
behaves like True).
2397+
2398+
scalex : bool
2399+
Whether to autoscale the x axis (default is True).
2400+
2401+
scaley : bool
2402+
Whether to autoscale the x axis (default is True).
2403+
2404+
Notes
2405+
-----
2406+
The autoscaling preserves any preexisting axis direction reversal.
23952407
23962408
The data limits are not updated automatically when artist data are
23972409
changed after the artist has been added to an Axes instance. In that

‎matplotlibrc.template

Copy file name to clipboardExpand all lines: matplotlibrc.template
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@
336336
## as opposed to the rest of this file.
337337
#axes.autolimit_mode : data ## How to scale axes limits to the data.
338338
## Use "data" to use data limits, plus some margin
339-
## Use "round_number" move to the nearest "round" number
339+
## Use "round_numbers" move to the nearest "round" number
340340
#axes.xmargin : .05 ## x margin. See `axes.Axes.margins`
341341
#axes.ymargin : .05 ## y margin See `axes.Axes.margins`
342342
#polaraxes.grid : True ## display grid on polar axes

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.