Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc00b89a

Browse files
committed
FIX: review suggestions
1 parent4e3cdce commitc00b89a

File tree

1 file changed

+36
-24
lines changed

1 file changed

+36
-24
lines changed

‎tutorials/intermediate/arranging_axes.py

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
sometimes useful for interactive work or to place an Axes in a custom
6767
location:
6868
69+
`~matplotlib.Figure.add_axes`
70+
Adds a single axes at a location specified by
71+
``[left, bottom, widtg, height]`` in fractions of figure width or height.
72+
6973
`~matplotlib.pyplot.subplot` or `.Figure.add_subplot`
7074
Adds a single subplot on a figure, with 1-based indexing (inherited from
7175
Matlab). Columns and rows can be spanned by specifying a range of grid
@@ -86,17 +90,16 @@
8690
# --------------
8791
#
8892
# We can create a basic 2-by-2 grid of Axes using
89-
# :func:`~matplotlib.pyplot.subplots`. It returns a
90-
# :class:`~matplotlib.figure.Figure` instance and an array of
91-
# :class:`~matplotlib.axes.Axes` objects. The Axes objects can
92-
# be used to access methods to place artists on the Axes; here we
93-
# use `~.Axes.annotate`, but other examples could be `~.Axes.plot`,
93+
# `~matplotlib.pyplot.subplots`. It returns a `~matplotlib.figure.Figure`
94+
# instance and an array of `~matplotlib.axes.Axes` objects. The Axes
95+
# objects can be used to access methods to place artists on the Axes; here
96+
# we use `~.Axes.annotate`, but other examples could be `~.Axes.plot`,
9497
# `~.Axes.pcolormesh`, etc.
9598

9699
importmatplotlib.pyplotasplt
97100
importnumpyasnp
98101

99-
fig,axs=plt.subplots(ncols=2,nrows=2,figsize=(4.5,3.5),
102+
fig,axs=plt.subplots(ncols=2,nrows=2,figsize=(5.5,3.5),
100103
constrained_layout=True)
101104
# add an artist, in this case a nice label in the middle...
102105
forrowinrange(2):
@@ -124,9 +127,9 @@ def annotate_axes(ax, text, fontsize=18):
124127
# representing a row, and each element in the list a key representing the
125128
# column.
126129

127-
fig,axd=plt.subplot_mosaic([['upleft','upright'],
128-
['loleft','loright']],
129-
figsize=(4.5,3.5),constrained_layout=True)
130+
fig,axd=plt.subplot_mosaic([['upper left','upper right'],
131+
['lower left','lower right']],
132+
figsize=(5.5,3.5),constrained_layout=True)
130133
forkinaxd.keys():
131134
annotate_axes(axd[k],f'axd["{k}"]',fontsize=14)
132135
fig.suptitle('plt.subplot_mosaic()')
@@ -140,9 +143,9 @@ def annotate_axes(ax, text, fontsize=18):
140143
# convenient is probably to use `~.pyplot.subplot_mosaic` by repeating one
141144
# of the keys:
142145

143-
fig,axd=plt.subplot_mosaic([['upleft','right'],
144-
['loleft','right']],
145-
figsize=(4.5,3.5),constrained_layout=True)
146+
fig,axd=plt.subplot_mosaic([['upper left','right'],
147+
['lower left','right']],
148+
figsize=(5.5,3.5),constrained_layout=True)
146149
forkinaxd.keys():
147150
annotate_axes(axd[k],f'axd["{k}"]',fontsize=14)
148151
fig.suptitle('plt.subplot_mosaic()')
@@ -157,14 +160,14 @@ def annotate_axes(ax, text, fontsize=18):
157160
# Both `~.pyplot.subplots` and `~.pyplot.subplot_mosaic` allow the rows
158161
# in the grid to be different heights, and the columns to be different
159162
# widths using the *gridspec_kw* keyword argument.
160-
# Spacing parameters accepted by:class:`~matplotlib.gridspec.GridSpec`
163+
# Spacing parameters accepted by `~matplotlib.gridspec.GridSpec`
161164
# can be passed to `~matplotlib.pyplot.subplots` and
162165
# `~matplotlib.pyplot.subplot_mosaic`:
163166

164167
gs_kw=dict(width_ratios=[1.4,1],height_ratios=[1,2])
165-
fig,axd=plt.subplot_mosaic([['upleft','right'],
166-
['loleft','right']],
167-
gridspec_kw=gs_kw,figsize=(4.5,3.5),
168+
fig,axd=plt.subplot_mosaic([['upper left','right'],
169+
['lower left','right']],
170+
gridspec_kw=gs_kw,figsize=(5.5,3.5),
168171
constrained_layout=True)
169172
forkinaxd.keys():
170173
annotate_axes(axd[k],f'axd["{k}"]',fontsize=14)
@@ -175,7 +178,7 @@ def annotate_axes(ax, text, fontsize=18):
175178
# -------------------
176179
#
177180
# Sometimes it is helpful to have two or more grids of Axes that
178-
# may not need to be related to one another. The most simple wayto
181+
# may not need to be related to one another. The most simple waytoin
179182
# accomplish this is to use `.Figure.subfigures`. Note that the alignement
180183
# of the subfigure layouts is independent with the Axes spines in each
181184
# subfigure having independent positions. See below for a more verbose
@@ -201,8 +204,8 @@ def annotate_axes(ax, text, fontsize=18):
201204

202205
inner= [['innerA'],
203206
['innerB']]
204-
outer= [['upleft',inner],
205-
['lowleft','lowright']]
207+
outer= [['upper left',inner],
208+
['lower left','lower right']]
206209

207210
fig,axd=plt.subplot_mosaic(outer,constrained_layout=True)
208211
forkinaxd.keys():
@@ -227,16 +230,21 @@ def annotate_axes(ax, text, fontsize=18):
227230
# We can accopmplish a 2x2 grid in the same manner as
228231
# ``plt.subplots(2, 2)``:
229232

230-
fig=plt.figure(figsize=(4.5,3.5),constrained_layout=True)
233+
fig=plt.figure(figsize=(5.5,3.5),constrained_layout=True)
231234
spec=fig.add_gridspec(ncols=2,nrows=2)
235+
232236
ax0=fig.add_subplot(spec[0,0])
233237
annotate_axes(ax0,'ax0')
238+
234239
ax1=fig.add_subplot(spec[0,1])
235240
annotate_axes(ax1,'ax1')
241+
236242
ax2=fig.add_subplot(spec[1,0])
237243
annotate_axes(ax2,'ax2')
244+
238245
ax3=fig.add_subplot(spec[1,1])
239246
annotate_axes(ax3,'ax3')
247+
240248
fig.suptitle('Manually added subplots using add_gridspec')
241249

242250
##############################################################################
@@ -248,14 +256,18 @@ def annotate_axes(ax, text, fontsize=18):
248256
# and the new Axes will span the slice. This would be the same
249257
# as ``fig, axd = plt.subplot_mosaic([['ax0', 'ax0'], ['ax1', 'ax2']], ...)``:
250258

251-
fig=plt.figure(figsize=(4.5,3.5),constrained_layout=True)
259+
fig=plt.figure(figsize=(5.5,3.5),constrained_layout=True)
252260
spec=fig.add_gridspec(2,2)
261+
253262
ax0=fig.add_subplot(spec[0, :])
254263
annotate_axes(ax0,'ax0')
264+
255265
ax10=fig.add_subplot(spec[1,0])
256266
annotate_axes(ax10,'ax10')
267+
257268
ax11=fig.add_subplot(spec[1,1])
258269
annotate_axes(ax11,'ax11')
270+
259271
fig.suptitle('Manually added subplots, spanning a column')
260272

261273
###############################################################################
@@ -288,7 +300,7 @@ def annotate_axes(ax, text, fontsize=18):
288300
# -------------------------------
289301
#
290302
# You can create nested layout similar to `~.Figure.subfigures` using
291-
# `~.gridspec.SubplotSpec.subgridspec`. Here the Axes spines_are_
303+
# `~.gridspec.SubplotSpec.subgridspec`. Here the Axes spines*are*
292304
# aligned.
293305
#
294306
# Note this is also available from the more verbose
@@ -316,7 +328,7 @@ def annotate_axes(ax, text, fontsize=18):
316328

317329
###############################################################################
318330
# Here's a more sophisticated example of nested *GridSpec*: We create an outer
319-
# 4x4 grid with each cell containingand inner 3x3 grid of Axes. We outline
331+
# 4x4 grid with each cell containingan inner 3x3 grid of Axes. We outline
320332
# the outer 4x4 grid by hiding appropriate spines in each of the inner 3x3
321333
# grids.
322334

@@ -352,7 +364,7 @@ def squiggle_xy(a, b, c, d, i=np.arange(0.0, 2*np.pi, 0.05)):
352364
# ============
353365
#
354366
# - More details about :doc:`subplot mosaic </tutorials/provisional/mosaic>`.
355-
# -more details about
367+
# -More details about
356368
# :doc:`constrained layout
357369
# </tutorials/intermediate/constrainedlayout_guide>`, used to align
358370
# spacing in most of these examples.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp