Skip to content

Commit b98c848

Browse files
authored
Merge pull request #29207 from meeseeksmachine/auto-backport-of-pr-29169-on-v3.10.x
Backport PR #29169 on branch v3.10.x (Minor fixes to text intro explainer)
2 parents 824d2f2 + 6b8eb4b commit b98c848

File tree

1 file changed

+38
-41
lines changed

1 file changed

+38
-41
lines changed

galleries/users_explain/text/text_intro.py

+38-41
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
Text in Matplotlib
99
==================
1010
11-
Introduction to plotting and working with text in Matplotlib.
12-
1311
Matplotlib has extensive text support, including support for
1412
mathematical expressions, truetype support for raster and
1513
vector outputs, newline separated text with arbitrary
@@ -124,8 +122,8 @@
124122
fig, ax = plt.subplots(figsize=(5, 3))
125123
fig.subplots_adjust(bottom=0.15, left=0.2)
126124
ax.plot(x1, y1)
127-
ax.set_xlabel('Time [s]')
128-
ax.set_ylabel('Damped oscillation [V]')
125+
ax.set_xlabel('Time (s)')
126+
ax.set_ylabel('Damped oscillation (V)')
129127

130128
plt.show()
131129

@@ -137,26 +135,26 @@
137135
fig, ax = plt.subplots(figsize=(5, 3))
138136
fig.subplots_adjust(bottom=0.15, left=0.2)
139137
ax.plot(x1, y1*10000)
140-
ax.set_xlabel('Time [s]')
141-
ax.set_ylabel('Damped oscillation [V]')
138+
ax.set_xlabel('Time (s)')
139+
ax.set_ylabel('Damped oscillation (V)')
142140

143141
plt.show()
144142

145143
# %%
146144
# If you want to move the labels, you can specify the *labelpad* keyword
147145
# argument, where the value is points (1/72", the same unit used to specify
148-
# fontsizes).
146+
# font sizes).
149147

150148
fig, ax = plt.subplots(figsize=(5, 3))
151149
fig.subplots_adjust(bottom=0.15, left=0.2)
152150
ax.plot(x1, y1*10000)
153-
ax.set_xlabel('Time [s]')
154-
ax.set_ylabel('Damped oscillation [V]', labelpad=18)
151+
ax.set_xlabel('Time (s)')
152+
ax.set_ylabel('Damped oscillation (V)', labelpad=18)
155153

156154
plt.show()
157155

158156
# %%
159-
# Or, the labels accept all the `.Text` keyword arguments, including
157+
# Alternatively, the labels accept all the `.Text` keyword arguments, including
160158
# *position*, via which we can manually specify the label positions. Here we
161159
# put the xlabel to the far left of the axis. Note, that the y-coordinate of
162160
# this position has no effect - to adjust the y-position we need to use the
@@ -165,15 +163,15 @@
165163
fig, ax = plt.subplots(figsize=(5, 3))
166164
fig.subplots_adjust(bottom=0.15, left=0.2)
167165
ax.plot(x1, y1)
168-
ax.set_xlabel('Time [s]', position=(0., 1e6), horizontalalignment='left')
169-
ax.set_ylabel('Damped oscillation [V]')
166+
ax.set_xlabel('Time (s)', position=(0., 1e6), horizontalalignment='left')
167+
ax.set_ylabel('Damped oscillation (V)')
170168

171169
plt.show()
172170

173171
# %%
174172
# All the labelling in this tutorial can be changed by manipulating the
175173
# `matplotlib.font_manager.FontProperties` method, or by named keyword
176-
# arguments to `~matplotlib.axes.Axes.set_xlabel`
174+
# arguments to `~matplotlib.axes.Axes.set_xlabel`.
177175

178176
from matplotlib.font_manager import FontProperties
179177

@@ -182,8 +180,8 @@
182180
fig, ax = plt.subplots(figsize=(5, 3))
183181
fig.subplots_adjust(bottom=0.15, left=0.2)
184182
ax.plot(x1, y1)
185-
ax.set_xlabel('Time [s]', fontsize='large', fontweight='bold')
186-
ax.set_ylabel('Damped oscillation [V]', fontproperties=font)
183+
ax.set_xlabel('Time (s)', fontsize='large', fontweight='bold')
184+
ax.set_ylabel('Damped oscillation (V)', fontproperties=font)
187185

188186
plt.show()
189187

@@ -194,8 +192,8 @@
194192
fig, ax = plt.subplots(figsize=(5, 3))
195193
fig.subplots_adjust(bottom=0.2, left=0.2)
196194
ax.plot(x1, np.cumsum(y1**2))
197-
ax.set_xlabel('Time [s] \n This was a long experiment')
198-
ax.set_ylabel(r'$\int\ Y^2\ dt\ \ [V^2 s]$')
195+
ax.set_xlabel('Time (s) \n This was a long experiment')
196+
ax.set_ylabel(r'$\int\ Y^2\ dt\ \ (V^2 s)$')
199197
plt.show()
200198

201199

@@ -204,14 +202,14 @@
204202
# ======
205203
#
206204
# Subplot titles are set in much the same way as labels, but there is
207-
# the *loc* keyword arguments that can change the position and justification
208-
# from the default value of ``loc=center``.
205+
# the *loc* keyword argument that can change the position and justification
206+
# (the default value is "center").
209207

210208
fig, axs = plt.subplots(3, 1, figsize=(5, 6), tight_layout=True)
211209
locs = ['center', 'left', 'right']
212210
for ax, loc in zip(axs, locs):
213211
ax.plot(x1, y1)
214-
ax.set_title('Title with loc at '+loc, loc=loc)
212+
ax.set_title('Title with loc at ' + loc, loc=loc)
215213
plt.show()
216214

217215
# %%
@@ -237,7 +235,7 @@
237235
# Terminology
238236
# ^^^^^^^^^^^
239237
#
240-
# *Axes* have an `matplotlib.axis.Axis` object for the ``ax.xaxis`` and
238+
# *Axes* have a `matplotlib.axis.Axis` object for the ``ax.xaxis`` and
241239
# ``ax.yaxis`` that contain the information about how the labels in the axis
242240
# are laid out.
243241
#
@@ -255,9 +253,9 @@
255253
#
256254
# It is often convenient to simply define the
257255
# tick values, and sometimes the tick labels, overriding the default
258-
# locators and formatters. This is discouraged because it breaks interactive
259-
# navigation of the plot. It also can reset the axis limits: note that
260-
# the second plot has the ticks we asked for, including ones that are
256+
# locators and formatters. However, this is discouraged because it breaks
257+
# interactive navigation of the plot. It also can reset the axis limits: note
258+
# that the second plot has the ticks we asked for, including ones that are
261259
# well outside the automatic view limits.
262260

263261
fig, axs = plt.subplots(2, 1, figsize=(5, 3), tight_layout=True)
@@ -283,7 +281,7 @@
283281
plt.show()
284282

285283
# %%
286-
# Tick Locators and Formatters
284+
# Tick locators and formatters
287285
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
288286
#
289287
# Instead of making a list of all the ticklabels, we could have
@@ -317,14 +315,14 @@
317315

318316
# %%
319317
# The default formatter is the `matplotlib.ticker.MaxNLocator` called as
320-
# ``ticker.MaxNLocator(self, nbins='auto', steps=[1, 2, 2.5, 5, 10])``
321-
# The *steps* keyword contains a list of multiples that can be used for
322-
# tick values. i.e. in this case, 2, 4, 6 would be acceptable ticks,
318+
# ``ticker.MaxNLocator(self, nbins='auto', steps=[1, 2, 2.5, 5, 10])``.
319+
# The ``steps`` argument contains a list of multiples that can be used for
320+
# tick values. In this case, 2, 4, 6 would be acceptable ticks,
323321
# as would 20, 40, 60 or 0.2, 0.4, 0.6. However, 3, 6, 9 would not be
324322
# acceptable because 3 doesn't appear in the list of steps.
325323
#
326-
# ``nbins=auto`` uses an algorithm to determine how many ticks will
327-
# be acceptable based on how long the axis is. The fontsize of the
324+
# Setting ``nbins=auto`` uses an algorithm to determine how many ticks will
325+
# be acceptable based on the axis length. The fontsize of the
328326
# ticklabel is taken into account, but the length of the tick string
329327
# is not (because it's not yet known.) In the bottom row, the
330328
# ticklabels are quite large, so we set ``nbins=4`` to make the
@@ -382,11 +380,11 @@ def formatoddticks(x, pos):
382380
# Matplotlib can accept `datetime.datetime` and `numpy.datetime64`
383381
# objects as plotting arguments. Dates and times require special
384382
# formatting, which can often benefit from manual intervention. In
385-
# order to help, dates have special Locators and Formatters,
383+
# order to help, dates have special locators and formatters,
386384
# defined in the `matplotlib.dates` module.
387385
#
388-
# A simple example is as follows. Note how we have to rotate the
389-
# tick labels so that they don't over-run each other.
386+
# The following simple example illustrates this concept. Note how we
387+
# rotate the tick labels so that they don't overlap.
390388

391389
import datetime
392390

@@ -399,11 +397,10 @@ def formatoddticks(x, pos):
399397
plt.show()
400398

401399
# %%
402-
# We can pass a format to `matplotlib.dates.DateFormatter`. Also note that the
403-
# 29th and the next month are very close together. We can fix this by using
404-
# the `.dates.DayLocator` class, which allows us to specify a list of days of
405-
# the month to use. Similar formatters are listed in the `matplotlib.dates`
406-
# module.
400+
# We can pass a format to `matplotlib.dates.DateFormatter`. If two tick labels
401+
# are very close together, we can use the `.dates.DayLocator` class, which
402+
# allows us to specify a list of days of the month to use. Similar formatters
403+
# are listed in the `matplotlib.dates` module.
407404

408405
import matplotlib.dates as mdates
409406

@@ -418,9 +415,9 @@ def formatoddticks(x, pos):
418415
plt.show()
419416

420417
# %%
421-
# Legends and Annotations
418+
# Legends and annotations
422419
# =======================
423420
#
424-
# - Legends: :ref:`legend_guide`
425-
# - Annotations: :ref:`annotations`
421+
# - :ref:`legend_guide`
422+
# - :ref:`annotations`
426423
#

0 commit comments

Comments
 (0)