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

Skip to content

Commit 06367ad

Browse files
timhoffmMeeseeksDev[bot]
authored andcommitted
Backport PR #14704: Small patches on Docs (Tutorials and FAQ)
1 parent 9a5473d commit 06367ad

4 files changed

Lines changed: 31 additions & 27 deletions

File tree

doc/faq/howto_faq.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
.. _howto-faq:
32

43
******
@@ -190,7 +189,8 @@ specify the location explicitly::
190189
ax = fig.add_axes([left, bottom, width, height])
191190

192191
where all values are in fractional (0 to 1) coordinates. See
193-
:doc:`/gallery/subplots_axes_and_figures/axes_demo` for an example of placing axes manually.
192+
:doc:`/gallery/subplots_axes_and_figures/axes_demo` for an example of
193+
placing axes manually.
194194

195195
.. _howto-auto-adjust:
196196

@@ -199,8 +199,11 @@ Automatically make room for tick labels
199199

200200
.. note::
201201
This is now easier to handle than ever before.
202-
Calling :func:`~matplotlib.pyplot.tight_layout` can fix many common
203-
layout issues. See the :doc:`/tutorials/intermediate/tight_layout_guide`.
202+
Calling :func:`~matplotlib.pyplot.tight_layout` or alternatively using
203+
``constrained_layout=True`` argument in :func:`~matplotlib.pyplot.subplots`
204+
can fix many common layout issues. See the
205+
:doc:`/tutorials/intermediate/tight_layout_guide` and
206+
:doc:`/tutorials/intermediate/constrainedlayout_guide` for more details.
204207

205208
The information below is kept here in case it is useful for other
206209
purposes.

tutorials/intermediate/constrainedlayout_guide.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def example_plot(ax, fontsize=12, nodec=False):
284284
# Spacing between subplots is set by ``wspace`` and ``hspace``. There are
285285
# specified as a fraction of the size of the subplot group as a whole.
286286
# If the size of the figure is changed, then these spaces change in
287-
# proportion. Note in the blow how the space at the edges doesn't change from
287+
# proportion. Note in the below how the space at the edges doesn't change from
288288
# the above, but the space between subplots does.
289289

290290
fig, axs = plt.subplots(2, 2, constrained_layout=True)

tutorials/intermediate/gridspec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@
137137

138138
gs_kw = dict(width_ratios=widths, height_ratios=heights)
139139
fig6, f6_axes = plt.subplots(ncols=3, nrows=3, constrained_layout=True,
140-
gridspec_kw=gs_kw)
140+
gridspec_kw=gs_kw)
141141
for r, row in enumerate(f6_axes):
142142
for c, ax in enumerate(row):
143143
label = 'Width: {}\nHeight: {}'.format(widths[c], heights[r])
144144
ax.annotate(label, (0.1, 0.5), xycoords='axes fraction', va='center')
145145

146146
############################################################################
147-
# The ``subplots`` and ``gridspec`` methods can be combined since it is
147+
# The ``subplots`` and ``get_gridspec`` methods can be combined since it is
148148
# sometimes more convenient to make most of the subplots using ``subplots``
149149
# and then remove some and combine them. Here we create a layout with
150150
# the bottom two axes in the last column combined.

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)