|
2 | 2 | Autoscaling
|
3 | 3 | ===========
|
4 | 4 |
|
5 |
| -Axis scales define the overall look of a plot, some default options |
6 |
| -scale ranges automatically with respect to supplied data - autoscaling. |
7 |
| -This tutorial shows concepts of individual autoscaling options and |
8 |
| -investigates cornerstone examples regarding the needs for manual adjustments. |
9 |
| -The limits on an axis can be set manually (e.g. ``ax.set_xlim(xmin, xmax)``) |
10 |
| -or Matplotlib can set them automatically based on the data already on the |
11 |
| -axes. There are a number of options to this autoscaling behaviour, |
12 |
| -discussed below. |
| 5 | +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. |
13 | 6 | """
|
14 | 7 |
|
15 | 8 | ###############################################################################
|
16 | 9 | # We will start with a simple line plot showing that autoscaling
|
17 |
| -# extends the visible range 5% beyond the real data range (-2π, 2π). |
| 10 | +# extends the axis limits 5% beyond the data limits (-2π, 2π). |
18 | 11 |
|
19 | 12 | import numpy as np
|
20 | 13 | import matplotlib as mpl
|
|
30 | 23 | ###############################################################################
|
31 | 24 | # Margins
|
32 | 25 | # -------
|
33 |
| -# The relative measure of the extend is called margin and can be set by |
34 |
| -# `~matplotlib.axes.Axes.margins`. |
35 |
| -# The default value is (0.05, 0.05): |
| 26 | +# The default margin around the data limits is 5%: |
36 | 27 |
|
37 | 28 | ax.margins()
|
38 | 29 |
|
39 | 30 | ###############################################################################
|
40 |
| -# The margins can be made larger: |
| 31 | +# The margins can be made larger using `~matplotlib.axes.Axes.margins`: |
41 | 32 |
|
42 | 33 | fig, ax = plt.subplots()
|
43 | 34 | ax.plot(x, y)
|
44 | 35 | ax.margins(0.2, 0.2)
|
45 | 36 | fig.show()
|
46 | 37 |
|
47 | 38 | ###############################################################################
|
48 |
| -# In general, margins shall be in range (-0.5, ∞), negative margins crop the |
49 |
| -# plot showing only a part of the data. Using a single number for margins |
| 39 | +# In general, margins can be in the range (-0.5, ∞), where negative margins set the axes limits to |
| 40 | +# a fraction of the data range, and allow a zoom effect. Using a single number for margins |
50 | 41 | # affects both axes, a single margin can be customized using keyword
|
51 | 42 | # arguments ``x`` or ``y``, but positional and keyword interface cannot be
|
52 | 43 | # combined
|
|
57 | 48 | fig.show()
|
58 | 49 |
|
59 | 50 | ###############################################################################
|
60 |
| -# There is the last keyword argument for margins call, the ``tight`` option. In |
61 |
| -# the case of a simple :func:`~matplotlib.axes.Axes.plot` call, this parameter |
62 |
| -# does not change anything, it is passed to the |
63 |
| -# :meth:`~matplotlib.axes.Axes.autoscale_view`, which requires more advanced |
64 |
| -# discussion. |
65 | 51 | #
|
66 |
| -# Margins can behave differently for certain plots, this is determined by |
67 |
| -# the sticky edges property, which is of interest in the next section. |
68 | 52 | #
|
69 | 53 | # Sticky edges
|
70 | 54 | # ------------
|
71 |
| -# Margin must not be applied for certain :class:`.Artist`, for example, setting |
| 55 | +# Some :class:`.Artist` objects do not allow margins. For example, setting |
72 | 56 | # ``margin=0.2`` on ``plt.imshow`` does not affect the resulting plot.
|
73 | 57 | #
|
74 | 58 |
|
|
84 | 68 | fig.show()
|
85 | 69 |
|
86 | 70 | ###############################################################################
|
87 |
| -# This override of margins is determined by so-called sticky edges. That is a |
88 |
| -# property of :class:`.Artist` class, which can suppress adding margins to data |
89 |
| -# limits. The effect of sticky edges can be disabled by changing |
90 |
| -# :class:`~matplotlib.axes.Axes` property |
91 |
| -# `~matplotlib.axes.Axes.use_sticky_edges`. |
92 |
| -# |
93 |
| -# Settings of sticky edges of individual artists can be investigating by |
94 |
| -# accessing them directly, `.Artist.sticky_edges`. Moreover, the values of |
| 71 | +# This override of margins is determined by "sticky edges", a |
| 72 | +# property of :class:`.Artist` class that can suppress adding margins to axis |
| 73 | +# limits. The effect of sticky edges can be disabled on an Axes by changing |
| 74 | +# `~matplotlib.axes.Axes.use_sticky_edges`. |
| 75 | +# Artists have a property `.Artist.sticky_edges`, and the values of |
95 | 76 | # sticky edges can be changed by writing to ``Artist.sticky_edges.x`` or
|
96 |
| -# ``.Artist.sticky_edges.y`` |
| 77 | +# ``.Artist.sticky_edges.y``. |
97 | 78 | #
|
98 | 79 | # The following example shows how overriding works and when it is needed.
|
99 | 80 |
|
|
0 commit comments