Skip to content

Commit 29d1b57

Browse files
authored
Merge pull request #21858 from meeseeksmachine/auto-backport-of-pr-21837-on-v3.5.0-doc
Backport PR #21837 on branch v3.5.0-doc (Display example figures in a single column)
2 parents db35fd7 + fe79005 commit 29d1b57

File tree

9 files changed

+52
-30
lines changed

9 files changed

+52
-30
lines changed

doc/_static/mpl.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ div.sphx-glr-download a:hover {
237237
background-color: #BCD4DF;
238238
}
239239

240+
/* Do not fold multiple figures in examples into two column layout. */
241+
img.sphx-glr-multi-img {
242+
max-width: 100%;
243+
}
244+
240245
table.property-table th,
241246
table.property-table td {
242247
padding: 4px 10px;

examples/images_contours_and_fields/barb_demo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
masked_u[4] = 1000 # Bad value that should not be plotted when masked
4848
masked_u[4] = np.ma.masked
4949

50+
#############################################################################
5051
# Identical plot to panel 2 in the first figure, but with the point at
5152
# (0.5, 0.25) missing (masked)
5253
fig2, ax2 = plt.subplots()

examples/images_contours_and_fields/contourf_demo.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@
3333
interior = np.sqrt(X**2 + Y**2) < 0.5
3434
Z[interior] = np.ma.masked
3535

36-
# We are using automatic selection of contour levels;
37-
# this is usually not such a good idea, because they don't
38-
# occur on nice boundaries, but we do it here for purposes
39-
# of illustration.
36+
#############################################################################
37+
# Automatic contour levels
38+
# ------------------------
39+
# We are using automatic selection of contour levels; this is usually not such
40+
# a good idea, because they don't occur on nice boundaries, but we do it here
41+
# for purposes of illustration.
4042

4143
fig1, ax2 = plt.subplots(constrained_layout=True)
4244
CS = ax2.contourf(X, Y, Z, 10, cmap=plt.cm.bone, origin=origin)
@@ -58,10 +60,13 @@
5860
# Add the contour line levels to the colorbar
5961
cbar.add_lines(CS2)
6062

63+
#############################################################################
64+
# Explicit contour levels
65+
# -----------------------
66+
# Now make a contour plot with the levels specified, and with the colormap
67+
# generated automatically from a list of colors.
68+
6169
fig2, ax2 = plt.subplots(constrained_layout=True)
62-
# Now make a contour plot with the levels specified,
63-
# and with the colormap generated automatically from a list
64-
# of colors.
6570
levels = [-1.5, -1, -0.5, 0, 0.5, 1]
6671
CS3 = ax2.contourf(X, Y, Z, levels,
6772
colors=('r', 'g', 'b'),
@@ -84,6 +89,9 @@
8489
# needs from the ContourSet object, CS3.
8590
fig2.colorbar(CS3)
8691

92+
#############################################################################
93+
# Extension settings
94+
# ------------------
8795
# Illustrate all 4 possible "extend" settings:
8896
extends = ["neither", "both", "min", "max"]
8997
cmap = plt.colormaps["winter"].with_extremes(under="magenta", over="yellow")

examples/images_contours_and_fields/image_demo.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,27 @@
4646
with cbook.get_sample_data('grace_hopper.jpg') as image_file:
4747
image = plt.imread(image_file)
4848

49-
fig, ax = plt.subplots()
50-
ax.imshow(image)
51-
ax.axis('off') # clear x-axis and y-axis
52-
53-
54-
# And another image
55-
56-
# Data are 256x256 16-bit integers.
49+
# And another image, using 256x256 16-bit integers.
5750
w, h = 256, 256
5851
with cbook.get_sample_data('s1045.ima.gz') as datafile:
5952
s = datafile.read()
6053
A = np.frombuffer(s, np.uint16).astype(float).reshape((w, h))
61-
62-
fig, ax = plt.subplots()
6354
extent = (0, 25, 0, 25)
64-
im = ax.imshow(A, cmap=plt.cm.hot, origin='upper', extent=extent)
55+
56+
fig, ax = plt.subplot_mosaic([
57+
['hopper', 'mri']
58+
], figsize=(7, 3.5))
59+
60+
ax['hopper'].imshow(image)
61+
ax['hopper'].axis('off') # clear x-axis and y-axis
62+
63+
im = ax['mri'].imshow(A, cmap=plt.cm.hot, origin='upper', extent=extent)
6564

6665
markers = [(15.9, 14.5), (16.8, 15)]
6766
x, y = zip(*markers)
68-
ax.plot(x, y, 'o')
67+
ax['mri'].plot(x, y, 'o')
6968

70-
ax.set_title('MRI')
69+
ax['mri'].set_title('MRI')
7170

7271
plt.show()
7372

examples/lines_bars_and_markers/fill_betweenx_demo.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@
2626
ax3.fill_betweenx(y, x1, x2)
2727
ax3.set_title('between (x1, x2)')
2828

29-
# now fill between x1 and x2 where a logical condition is met. Note
30-
# this is different than calling
29+
#############################################################################
30+
# Now fill between x1 and x2 where a logical condition is met. Note this is
31+
# different than calling::
32+
#
3133
# fill_between(y[where], x1[where], x2[where])
34+
#
3235
# because of edge effects over multiple contiguous regions.
3336

3437
fig, [ax, ax1] = plt.subplots(1, 2, sharey=True, figsize=(6, 6))
@@ -44,9 +47,9 @@
4447
ax1.fill_betweenx(y, x1, x2, where=x2 <= x1, facecolor='red')
4548
ax1.set_title('regions with x2 > 1 are masked')
4649

47-
# This example illustrates a problem; because of the data
48-
# gridding, there are undesired unfilled triangles at the crossover
49-
# points. A brute-force solution would be to interpolate all
50-
# arrays to a very fine grid before plotting.
50+
#############################################################################
51+
# This example illustrates a problem; because of the data gridding, there are
52+
# undesired unfilled triangles at the crossover points. A brute-force solution
53+
# would be to interpolate all arrays to a very fine grid before plotting.
5154

5255
plt.show()

examples/text_labels_and_annotations/accented_text.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
ax.text(4, 0.5, r"$F=m\ddot{x}$")
2525
fig.tight_layout()
2626

27-
# Unicode demo
27+
#############################################################################
28+
# You can also use Unicode characters directly in strings.
2829
fig, ax = plt.subplots()
2930
ax.set_title("GISCARD CHAHUTÉ À L'ASSEMBLÉE")
3031
ax.set_xlabel("LE COUP DE DÉ DE DE GAULLE")

examples/text_labels_and_annotations/annotation_demo.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
horizontalalignment='left',
126126
verticalalignment='bottom')
127127

128+
#############################################################################
128129
# You can also use polar notation on a cartesian axes. Here the native
129130
# coordinate system ('data') is cartesian, so you need to specify the
130131
# xycoords and textcoords as 'polar' if you want to use (theta, radius).
@@ -230,6 +231,7 @@
230231

231232
ax.set(xlim=(-1, 5), ylim=(-4, 3))
232233

234+
#############################################################################
233235
# We'll create another figure so that it doesn't get too cluttered
234236
fig, ax = plt.subplots()
235237

examples/ticks/tick-formatters.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ def setup(ax, title):
3434
fontsize=14, fontname='Monospace', color='tab:blue')
3535

3636

37+
#############################################################################
3738
# Tick formatters can be set in one of two ways, either by passing a ``str``
3839
# or function to `~.Axis.set_major_formatter` or `~.Axis.set_minor_formatter`,
3940
# or by creating an instance of one of the various `~.ticker.Formatter` classes
4041
# and providing that to `~.Axis.set_major_formatter` or
4142
# `~.Axis.set_minor_formatter`.
42-
43+
#
4344
# The first two examples directly pass a ``str`` or function.
4445

4546
fig0, axs0 = plt.subplots(2, 1, figsize=(8, 2))
@@ -53,14 +54,15 @@ def setup(ax, title):
5354

5455
# A function can also be used directly as a formatter. The function must take
5556
# two arguments: ``x`` for the tick value and ``pos`` for the tick position,
56-
# and must return a ``str`` This creates a FuncFormatter automatically.
57+
# and must return a ``str``. This creates a FuncFormatter automatically.
5758
setup(axs0[1], title="lambda x, pos: str(x-5)")
5859
axs0[1].xaxis.set_major_formatter(lambda x, pos: str(x-5))
5960

6061
fig0.tight_layout()
6162

6263

63-
# The remaining examples use Formatter objects.
64+
#############################################################################
65+
# The remaining examples use `.Formatter` objects.
6466

6567
fig1, axs1 = plt.subplots(7, 1, figsize=(8, 6))
6668
fig1.suptitle('Formatter Object Formatting')

examples/userdemo/demo_gridspec03.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def annotate_axes(fig):
3131

3232
annotate_axes(fig)
3333

34+
#############################################################################
3435

3536
fig = plt.figure()
3637
fig.suptitle("Controlling spacing around and between subplots")

0 commit comments

Comments
 (0)