|
7 | 7 | This tutorial shows concepts of individual autoscaling options and
|
8 | 8 | investigates cornerstone examples regarding the needs for manual adjustments.
|
9 | 9 | """
|
| 10 | +The limits on an axis can be set manually (e.g. ``ax.set_xlim(xmin, xmax)``) or Matplotlib can set them automatically based on the data already on the axes. There are a number of options to this autoscaling behaviour, discussed below. |
10 | 11 |
|
11 | 12 | ###############################################################################
|
12 |
| -# We will start with a simple line plot showing that the autoscaling feature |
13 |
| -# extends the visible range slightly beyond the real data range (-2π, 2π). |
| 13 | +# We will start with a simple line plot showing that autoscaling |
| 14 | +# extends the visible range 5% beyond the real data range (-2π, 2π). |
14 | 15 |
|
15 | 16 | import numpy as np
|
16 | 17 | import matplotlib as mpl
|
|
27 | 28 | # Margins
|
28 | 29 | # -------
|
29 | 30 | # The relative measure of the extend is called margin and can be set by
|
30 |
| -# :func:`~matplotlib.axes.Axes.margins`. |
31 |
| -# We can check that the default value is (0.05, 0.05). |
| 31 | +# `~matplotlib.axes.Axes.margins`. |
| 32 | +# The default value is (0.05, 0.05): |
32 | 33 |
|
33 | 34 | ax.margins()
|
34 | 35 |
|
35 | 36 | ###############################################################################
|
36 |
| -# Margin scales with respect to the data interval so setting a larger margin |
37 |
| -# ensures more space between actual data and plot edges, hence plotted curve |
38 |
| -# will appear smaller. |
| 37 | +# The margins can be made larger: |
39 | 38 |
|
40 | 39 | fig, ax = plt.subplots()
|
41 | 40 | ax.plot(x, y)
|
|
118 | 117 | # Controlling autoscale
|
119 | 118 | # ---------------------
|
120 | 119 | #
|
121 |
| -# We have figured out how to control the margins of the plot. Now, we will |
122 |
| -# investigate how to disable autoscaling. By default, the scales are |
| 120 | +# It is possible to disable autoscaling. By default, the limits are |
123 | 121 | # recalculated every time you add a new curve to the plot (see next figure).
|
124 |
| -# This ensures the visibility of the data. However, there are cases when you |
125 |
| -# don't want to automatically adjust viewport to data. |
| 122 | +# However, there are cases when you don't want to automatically adjust the |
| 123 | +viewport to new data. |
126 | 124 |
|
127 | 125 | fig, ax = plt.subplots(ncols=2, figsize=(12, 8))
|
128 | 126 | ax[0].plot(x, y)
|
|
134 | 132 |
|
135 | 133 |
|
136 | 134 | ###############################################################################
|
137 |
| -# There are multiple reasons to do that so there are multiple ways of |
138 |
| -# disabling the autoscale feature. One of the cases is manually setting the |
| 135 | +# One way to disable autoscaling is to manually setting the |
139 | 136 | # axis limit. Let's say that we want to see only a part of the data in
|
140 | 137 | # greater detail. Setting the ``xlim`` persists even if we add more curves to
|
141 |
| -# the data. To recalculate the new limits we shall call `.Axes.autoscale` |
142 |
| -# manually to toggle the functionality. |
| 138 | +# the data. To recalculate the new limits calling `.Axes.autoscale` will |
| 139 | +# manually toggle the functionality. |
143 | 140 |
|
144 | 141 | fig, ax = plt.subplots(ncols=2, figsize=(12, 8))
|
145 | 142 | ax[0].plot(x, y)
|
|
165 | 162 | # of autoscaling. A combination of arguments ``enable``, and ``axis`` sets the
|
166 | 163 | # autoscaling feature for the selected axis (or both). The argument ``tight``
|
167 | 164 | # sets the margin of the selected axis to zero. To preserve settings of either
|
168 |
| -# ``enable`` or ``tight`` you can set the opposite one to None, that way |
169 |
| -# it should not be modified. However, setting ``enable`` to None and tight |
170 |
| -# to True affects both axes regardless of the ``axis`` argument. |
| 165 | +# ``enable`` or ``tight`` you can set the opposite one to *None*, that way |
| 166 | +# it should not be modified. However, setting ``enable`` to *None* and tight |
| 167 | +# to *True* affects both axes regardless of the ``axis`` argument. |
171 | 168 |
|
172 | 169 | fig, ax = plt.subplots()
|
173 | 170 | ax.plot(x, y)
|
|
182 | 179 | # Autoscale works out of the box for all lines, patches, and images added to
|
183 | 180 | # the axes. One of the artists that it won't work with is a `.Collection`.
|
184 | 181 | # After adding a collection to the axes, one has to manually trigger the
|
185 |
| -# :func:`~matplotlib.axes.Axes.autoscale_view()` to propagate recalculated |
186 |
| -# limits to the figure. |
| 182 | +# `~matplotlib.axes.Axes.autoscale_view()` to recalculate |
| 183 | +# axes limits. |
187 | 184 |
|
188 | 185 | fig, ax = plt.subplots()
|
189 | 186 | collection = mpl.collections.StarPolygonCollection(
|
|
0 commit comments