Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 733fc54

Browse files
deep-jkljklymak
authored and
Jakub Klus
committed
Apply suggestions from code review
Many thanks to @jklymak. I accept the suggestions as they are, but I sense that there will be need for some code fixups. Co-authored-by: Jody Klymak <[email protected]>
1 parent 3fe97d3 commit 733fc54

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

tutorials/intermediate/autoscale.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
This tutorial shows concepts of individual autoscaling options and
88
investigates cornerstone examples regarding the needs for manual adjustments.
99
"""
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.
1011

1112
###############################################################################
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π).
1415

1516
import numpy as np
1617
import matplotlib as mpl
@@ -27,15 +28,13 @@
2728
# Margins
2829
# -------
2930
# 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):
3233

3334
ax.margins()
3435

3536
###############################################################################
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:
3938

4039
fig, ax = plt.subplots()
4140
ax.plot(x, y)
@@ -118,11 +117,10 @@
118117
# Controlling autoscale
119118
# ---------------------
120119
#
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
123121
# 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.
126124

127125
fig, ax = plt.subplots(ncols=2, figsize=(12, 8))
128126
ax[0].plot(x, y)
@@ -134,12 +132,11 @@
134132

135133

136134
###############################################################################
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
139136
# axis limit. Let's say that we want to see only a part of the data in
140137
# 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.
143140

144141
fig, ax = plt.subplots(ncols=2, figsize=(12, 8))
145142
ax[0].plot(x, y)
@@ -165,9 +162,9 @@
165162
# of autoscaling. A combination of arguments ``enable``, and ``axis`` sets the
166163
# autoscaling feature for the selected axis (or both). The argument ``tight``
167164
# 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.
171168

172169
fig, ax = plt.subplots()
173170
ax.plot(x, y)
@@ -182,8 +179,8 @@
182179
# Autoscale works out of the box for all lines, patches, and images added to
183180
# the axes. One of the artists that it won't work with is a `.Collection`.
184181
# 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.
187184

188185
fig, ax = plt.subplots()
189186
collection = mpl.collections.StarPolygonCollection(

0 commit comments

Comments
 (0)