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

Skip to content

Commit f6a7427

Browse files
committed
Add some small patches to Text Intro Guide.
1 parent f0fe167 commit f6a7427

1 file changed

Lines changed: 21 additions & 20 deletions

File tree

tutorials/text/text_intro.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,19 @@
6969
import matplotlib.pyplot as plt
7070

7171
fig = plt.figure()
72-
fig.suptitle('bold figure suptitle', fontsize=14, fontweight='bold')
73-
7472
ax = fig.add_subplot(111)
7573
fig.subplots_adjust(top=0.85)
74+
75+
# Set titles for the figure and the subplot respectively
76+
fig.suptitle('bold figure suptitle', fontsize=14, fontweight='bold')
7677
ax.set_title('axes title')
7778

7879
ax.set_xlabel('xlabel')
7980
ax.set_ylabel('ylabel')
8081

82+
# Set both x- and y-axis limits to [0, 10] instead of default [0, 1]
83+
ax.axis([0, 10, 0, 10])
84+
8185
ax.text(3, 8, 'boxed italics text in data coords', style='italic',
8286
bbox={'facecolor': 'red', 'alpha': 0.5, 'pad': 10})
8387

@@ -90,13 +94,10 @@
9094
transform=ax.transAxes,
9195
color='green', fontsize=15)
9296

93-
9497
ax.plot([2], [1], 'o')
9598
ax.annotate('annotate', xy=(2, 1), xytext=(3, 4),
9699
arrowprops=dict(facecolor='black', shrink=0.05))
97100

98-
ax.axis([0, 10, 0, 10])
99-
100101
plt.show()
101102

102103
###############################################################################
@@ -157,8 +158,7 @@
157158
fig, ax = plt.subplots(figsize=(5, 3))
158159
fig.subplots_adjust(bottom=0.15, left=0.2)
159160
ax.plot(x1, y1)
160-
ax.set_xlabel('time [s]', position=(0., 1e6),
161-
horizontalalignment='left')
161+
ax.set_xlabel('time [s]', position=(0., 1e6), horizontalalignment='left')
162162
ax.set_ylabel('Damped oscillation [V]')
163163

164164
plt.show()
@@ -226,34 +226,33 @@
226226
# ====================
227227
#
228228
# Placing ticks and ticklabels is a very tricky aspect of making a figure.
229-
# Matplotlib does the best it can automatically, but it also offers a very
230-
# flexible framework for determining the choices for tick locations, and
231-
# how they are labelled.
229+
# Matplotlib does its best to accomplish the task automatically, but it also
230+
# offers a very flexible framework for determining the choices for tick
231+
# locations, and how they are labelled.
232232
#
233233
# Terminology
234234
# ~~~~~~~~~~~
235235
#
236-
# *Axes* have an `matplotlib.axis` object for the ``ax.xaxis``
237-
# and ``ax.yaxis`` that
238-
# contain the information about how the labels in the axis are laid out.
236+
# *Axes* have a `matplotlib.axis` object for the ``ax.xaxis`` and ``ax.yaxis``
237+
# that contain the information about how the labels in the axis are laid out.
239238
#
240239
# The axis API is explained in detail in the documentation to
241240
# `~matplotlib.axis`.
242241
#
243-
# An Axis object has major and minor ticks. The Axis has a
242+
# An Axis object has major and minor ticks. The Axis has
244243
# `matplotlib.xaxis.set_major_locator` and
245244
# `matplotlib.xaxis.set_minor_locator` methods that use the data being plotted
246245
# to determine
247246
# the location of major and minor ticks. There are also
248247
# `matplotlib.xaxis.set_major_formatter` and
249-
# `matplotlib.xaxis.set_minor_formatters` methods that format the tick labels.
248+
# `matplotlib.xaxis.set_minor_formatter` methods that format the tick labels.
250249
#
251250
# Simple ticks
252251
# ~~~~~~~~~~~~
253252
#
254253
# It often is convenient to simply define the
255254
# tick values, and sometimes the tick labels, overriding the default
256-
# locators and formatters. This is discouraged because it breaks itneractive
255+
# locators and formatters. This is discouraged because it breaks interactive
257256
# navigation of the plot. It also can reset the axis limits: note that
258257
# the second plot has the ticks we asked for, including ones that are
259258
# well outside the automatic view limits.
@@ -285,8 +284,9 @@
285284
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
286285
#
287286
# Instead of making a list of all the tickalbels, we could have
288-
# used a `matplotlib.ticker.FormatStrFormatter` and passed it to the
289-
# ``ax.xaxis``
287+
# used `matplotlib.ticker.StrMethodFormatter` (new-style ``str.format()``
288+
# format string) or `matplotlib.ticker.FormatStrFormatter` (old-style '%'
289+
# format string) and passed it to the ``ax.xaxis``.
290290

291291
fig, axs = plt.subplots(2, 1, figsize=(5, 3), tight_layout=True)
292292
axs[0].plot(x1, y1)
@@ -362,6 +362,7 @@ def formatoddticks(x, pos):
362362
else:
363363
return ''
364364

365+
365366
fig, ax = plt.subplots(figsize=(5, 3), tight_layout=True)
366367
ax.plot(x1, y1)
367368
formatter = matplotlib.ticker.FuncFormatter(formatoddticks)
@@ -383,17 +384,17 @@ def formatoddticks(x, pos):
383384
#
384385
# A simple example is as follows. Note how we have to rotate the
385386
# tick labels so that they don't over-run each other.
387+
386388
import datetime
387389

388390
fig, ax = plt.subplots(figsize=(5, 3), tight_layout=True)
389391
base = datetime.datetime(2017, 1, 1, 0, 0, 1)
390-
time = [base + datetime.timedelta(days=x) for x in range(len(y1))]
392+
time = [base + datetime.timedelta(days=x) for x in range(len(x1))]
391393

392394
ax.plot(time, y1)
393395
ax.tick_params(axis='x', rotation=70)
394396
plt.show()
395397

396-
397398
##############################################################################
398399
# We can pass a format
399400
# to `matplotlib.dates.DateFormatter`. Also note that the 29th and the

0 commit comments

Comments
 (0)