8000 Merge pull request #8899 from tonyyli/sep-multiplot · matplotlib/matplotlib@b781623 · GitHub
[go: up one dir, main page]

Skip to content

Commit b781623

Browse files
authored
Merge pull request #8899 from tonyyli/sep-multiplot
Separating examples with multiple plots into separate blocks
2 parents 411fbf6 + 1e162f0 commit b781623

33 files changed

+295
-94
lines changed

examples/animation/basic_example.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def update_line(num, data, line):
1616
line.set_data(data[..., :num])
1717
return line,
1818

19+
###############################################################################
20+
1921
fig1 = plt.figure()
2022

2123
# Fixing random state for reproducibility
@@ -32,6 +34,8 @@ def update_line(num, data, line):
3234

3335
# To save the animation, use the command: line_ani.save('lines.mp4')
3436

37+
###############################################################################
38+
3539
fig2 = plt.figure()
3640

3741
x = np.arange(-9, 10)

examples/api/filled_step.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ def stack_hist(ax, stacked_data, sty_cycle, bottoms=None,
191191
stack_data = np.random.randn(4, 12250)
192192
dict_data = OrderedDict(zip((c['label'] for c in label_cycle), stack_data))
193193

194-
# work with plain arrays
194+
###############################################################################
195+
# Work with plain arrays
196+
195197
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(9, 4.5), tight_layout=True)
196198
arts = stack_hist(ax1, stack_data, color_cycle + label_cycle + hatch_cycle,
197199
hist_func=hist_func)
@@ -204,7 +206,8 @@ def stack_hist(ax, stacked_data, sty_cycle, bottoms=None,
204206
ax2.set_xlabel('counts')
205207
ax2.set_ylabel('x')
206208

207-
# work with labeled data
209+
###############################################################################
210+
# Work with labeled data
208211

209212
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(9, 4.5),
210213
tight_layout=True, sharey=True)

examples/api/sankey_basics.py

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,42 @@
1111
from matplotlib.sankey import Sankey
1212

1313

14+
###############################################################################
1415
# Example 1 -- Mostly defaults
16+
#
1517
# This demonstrates how to create a simple diagram by implicitly calling the
1618
# Sankey.add() method and by appending finish() to the call to the class.
19+
1720
Sankey(flows=[0.25, 0.15, 0.60, -0.20, -0.15, -0.05, -0.50, -0.10],
1821
labels=['', '', '', 'First', 'Second', 'Third', 'Fourth', 'Fifth'],
1922
orientations=[-1, 1, 0, 1, 1, 1, 0, -1]).finish()
2023
plt.title("The default settings produce a diagram like this.")
24+
25+
###############################################################################
2126
# Notice:
22-
# 1. Axes weren't provided when Sankey() was instantiated, so they were
23-
# created automatically.
24-
# 2. The scale argument wasn't necessary since the data was already
25-
# normalized.
26-
# 3. By default, the lengths of the paths are justified.
27+
#
28+
# 1. Axes weren't provided when Sankey() was instantiated, so they were
29+
# created automatically.
30+
# 2. The scale argument wasn't necessary since the data was already
31+
# normalized.
32+
# 3. By default, the lengths of the paths are justified.
2733

34+
35+
###############################################################################
2836
# Example 2
37+
#
2938
# This demonstrates:
30-
# 1. Setting one path longer than the others
31-
# 2. Placing a label in the middle of the diagram
32-
# 3. Using the scale argument to normalize the flows
33-
# 4. Implicitly passing keyword arguments to PathPatch()
34-
# 5. Changing the angle of the arrow heads
35-
# 6. Changing the offset between the tips of the paths and their labels
36-
# 7. Formatting the numbers in the path labels and the associated unit
37-
# 8. Changing the appearance of the patch and the labels after the figure is
38-
# created
39+
#
40+
# 1. Setting one path longer than the others
41+
# 2. Placing a label in the middle of the diagram
42+
# 3. Using the scale argument to normalize the flows
43+
# 4. Implicitly passing keyword arguments to PathPatch()
44+
# 5. Changing the angle of the arrow heads
45+
# 6. Changing the offset between the tips of the paths and their labels
46+
# 7. Formatting the numbers in the path labels and the associated unit
47+
# 8. Changing the appearance of the patch and the labels after the figure is
48+
# created
49+
3950
fig = plt.figure()
4051
ax = fig.add_subplot(1, 1, 1, xticks=[], yticks=[],
4152
title="Flow Diagram of a Widget")
@@ -51,18 +62,26 @@
5162
diagrams = sankey.finish()
5263
diagrams[0].texts[-1].set_color('r')
5364
diagrams[0].text.set_fontweight('bold')
65+
66+
###############################################################################
5467
# Notice:
55-
# 1. Since the sum of the flows is nonzero, the width of the trunk isn't
56-
# uniform. If verbose.level is helpful (in matplotlibrc), a message is
57-
# given in the terminal window.
58-
# 2. The second flow doesn't appear because its value is zero. Again, if
59-
# verbose.level is helpful, a message is given in the terminal window.
68+
#
69+
# 1. Since the sum of the flows is nonzero, the width of the trunk isn't
70+
# uniform. If verbose.level is helpful (in matplotlibrc), a message is
71+
# given in the terminal window.
72+
# 2. The second flow doesn't appear because its value is zero. Again, if
73+
# verbose.level is helpful, a message is given in the terminal window.
74+
6075

76+
###############################################################################
6177
# Example 3
78+
#
6279
# This demonstrates:
63-
# 1. Connecting two systems
64-
# 2. Turning off the labels of the quantities
65-
# 3. Adding a legend
80+
#
81+
# 1. Connecting two systems
82+
# 2. Turning off the labels of the quantities
83+
# 3. Adding a legend
84+
6685
fig = plt.figure()
6786
ax = fig.add_subplot(1, 1, 1, xticks=[], yticks=[], title="Two Systems")
6887
flows = [0.25, 0.15, 0.60, -0.10, -0.05, -0.25, -0.15, -0.10, -0.35]
@@ -74,6 +93,8 @@
7493
diagrams = sankey.finish()
7594
diagrams[-1].patch.set_hatch('/')
7695
plt.legend(loc='best')
96+
97+
###############################################################################
7798
# Notice that only one connection is specified, but the systems form a
7899
# circuit since: (1) the lengths of the paths are justified and (2) the
79100
# orientation and ordering of the flows is mirrored.

examples/event_handling/figure_axes_enter_leave.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ def leave_figure(event):
3333
event.canvas.figure.patch.set_facecolor('grey')
3434
event.canvas.draw()
3535

36+
###############################################################################
37+
3638
fig1, (ax, ax2) = plt.subplots(2, 1)
3739
fig1.suptitle('mouse hover over figure or axes to trigger events')
3840

@@ -41,6 +43,8 @@ def leave_figure(event):
4143
fig1.canvas.mpl_connect('axes_enter_event', enter_axes)
4244
fig1.canvas.mpl_connect('axes_leave_event', leave_axes)
4345

46+
###############################################################################
47+
4448
fig2, (ax, ax2) = plt.subplots(2, 1)
4549
fig2.suptitle('mouse hover over figure or axes to trigger events')
4650

examples/images_contours_and_fields/contour_demo.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,43 @@
2626
# difference of Gaussians
2727
Z = 10.0 * (Z2 - Z1)
2828

29-
29+
###############################################################################
3030
# Create a simple contour plot with labels using default colors. The
3131
# inline argument to clabel will control whether the labels are draw
3232
# over the line segments of the contour, removing the lines beneath
3333
# the label
34+
3435
plt.figure()
3536
CS = plt.contour(X, Y, Z)
3637
plt.clabel(CS, inline=1, fontsize=10)
3738
plt.title('Simplest default with labels')
3839

3940

41+
###############################################################################
4042
# contour labels can be placed manually by providing list of positions
4143
# (in data coordinate). See ginput_manual_clabel.py for interactive
4244
# placement.
45+
4346
plt.figure()
4447
CS = plt.contour(X, Y, Z)
4548
manual_locations = [(-1, -1.4), (-0.62, -0.7), (-2, 0.5), (1.7, 1.2), (2.0, 1.4), (2.4, 1.7)]
4649
plt.clabel(CS, inline=1, fontsize=10, manual=manual_locations)
4750
plt.title('labels at selected locations')
4851

4952

53+
###############################################################################
5054
# You can force all the contours to be the same color.
55+
5156
plt.figure()
5257
CS = plt.contour(X, Y, Z, 6,
5358
colors='k', # negative contours will be dashed by default
5459
)
5560
plt.clabel(CS, fontsize=9, inline=1)
5661
plt.title('Single color - negative contours dashed')
5762

63+
###############################################################################
5864
# You can set negative contours to be solid instead of dashed:
65+
5966
matplotlib.rcParams['contour.negative_linestyle'] = 'solid'
6067
plt.figure()
6168
CS = plt.contour(X, Y, Z, 6,
@@ -65,7 +72,9 @@
6572
plt.title('Single color - negative contours solid')
6673

6774

75+
###############################################################################
6876
# And you can manually specify the colors of the contour
77+
6978
plt.figure()
7079
CS = plt.contour(X, Y, Z, 6,
7180
linewidths=np.arange(.5, 4, .5),
@@ -75,8 +84,10 @@
7584
plt.title('Crazy lines')
7685

7786

87+
###############################################################################
7888
# Or you can use a colormap to specify the colors; the default
7989
# colormap will be used for the contour lines
90+
8091
plt.figure()
8192
im = plt.imshow(Z, interpolation='bilinear', origin='lower',
8293
cmap=cm.gray, extent=(-3, 3, -2, 2))

examples/images_contours_and_fields/contour_label_demo.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
matplotlib.rcParams['xtick.direction'] = 'out'
1919
matplotlib.rcParams['ytick.direction'] = 'out'
2020

21-
##################################################
21+
###############################################################################
2222
# Define our surface
23+
2324
delta = 0.025
2425
x = np.arange(-3.0, 3.0, delta)
2526
y = np.arange(-2.0, 2.0, delta)
@@ -29,9 +30,10 @@
2930
# difference of Gaussians
3031
Z = 10.0 * (Z2 - Z1)
3132

32-
##################################################
33+
###############################################################################
3334
# Make contour labels using creative float classes
3435
# Follows suggestion of Manuel Metz
36+
3537
plt.figure()
3638

3739
# Basic contour plot
@@ -59,9 +61,9 @@ def __repr__(self):
5961
fmt = '%r %%'
6062
plt.clabel(CS, CS.levels, inline=True, fmt=fmt, fontsize=10)
6163

62-
##################################################
63-
# Label contours with arbitrary strings using a
64-
# dictionary
64+
###############################################################################
65+
# Label contours with arbitrary strings using a dictionary
66+
6567
plt.figure()
6668

6769
# Basic contour plot
@@ -75,6 +77,7 @@ def __repr__(self):
7577
# Label every other level using strings
7678
plt.clabel(CS, CS.levels[::2], inline=True, fmt=fmt, fontsize=10)
7779

80+
###############################################################################
7881
# Use a Formatter
7982

8083
plt.figure()

examples/images_contours_and_fields/contourf_hatching.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import matplotlib.pyplot as plt
99
import numpy as np
1010

11-
1211
# invent some numbers, turning the x and y arrays into simple
1312
# 2d arrays, which make combining them together easier.
1413
x = np.linspace(-3, 5, 150).reshape(1, -1)
@@ -18,22 +17,19 @@
1817
# we no longer need x and y to be 2 dimensional, so flatten them.
1918
x, y = x.flatten(), y.flatten()
2019

20+
###############################################################################
21+
# Plot 1: the simplest hatched plot with a colorbar
2122

22-
# ---------------------------------------------
23-
# | Plot #1 |
24-
# ---------------------------------------------
25-
# the simplest hatched plot with a colorbar
2623
fig = plt.figure()
2724
cs = plt.contourf(x, y, z, hatches=['-', '/', '\\', '//'],
2825
cmap=plt.get_cmap('gray'),
2926
extend='both', alpha=0.5
3027
)
3128
plt.colorbar()
3229

33-
# ---------------------------------------------
34-
# | Plot #2 |
35-
# ---------------------------------------------
36-
# a plot of hatches without color with a legend
30+
###############################################################################
31+
# Plot 2: a plot of hatches without color with a legend
32+
3733
plt.figure()
3834
n_levels = 6
3935
plt.contour(x, y, z, n_levels, colors='black', linestyles='-')

examples/images_contours_and_fields/quiver_demo.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@
1616
U = np.cos(X)
1717
V = np.sin(Y)
1818

19+
###############################################################################
20+
1921
plt.figure()
2022
plt.title('Arrows scale with plot width, not view')
2123
Q = plt.quiver(X, Y, U, V, units='width')
2224
qk = plt.quiverkey(Q, 0.9, 0.9, 2, r'$2 \frac{m}{s}$', labelpos='E',
2325
coordinates='figure')
2426

27+
###############################################################################
28+
2529
plt.figure()
2630
plt.title("pivot='mid'; every third arrow; units='inches'")
2731
Q = plt.quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3],
@@ -30,6 +34,8 @@
3034
coordinates='figure')
3135
plt.scatter(X[::3, ::3], Y[::3, ::3], color='r', s=5)
3236

37+
###############################################################################
38+
3339
plt.figure()
3440
plt.title("pivot='tip'; scales with x view")
3541
M = np.hypot(U, V)

examples/images_contours_and_fields/tricontour_demo.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import numpy as np
1111
import math
1212

13+
###############################################################################
1314
# Creating a Triangulation without specifying the triangles results in the
1415
# Delaunay triangulation of the points.
1516

@@ -36,14 +37,17 @@
3637
mask = np.where(xmid * xmid + ymid * ymid < min_radius * min_radius, 1, 0)
3738
triang.set_mask(mask)
3839

40+
###############################################################################
3941
# pcolor plot.
42+
4043
plt.figure()
4144
plt.gca().set_aspect('equal')
4245
plt.tricontourf(triang, z)
4346
plt.colorbar()
4447
plt.tricontour(triang, z, colors='k')
4548
plt.title('Contour plot of Delaunay triangulation')
4649

50+
###############################################################################
4751
# You can specify your own triangulation rather than perform a Delaunay
4852
# triangulation of the points, where each triangle is given by the indices of
4953
# the three points that make up the triangle, ordered in either a clockwise or
@@ -93,10 +97,12 @@
9397
[42, 41, 40], [72, 33, 31], [32, 31, 33], [39, 38, 72], [33, 72, 38],
9498
[33, 38, 34], [37, 35, 38], [34, 38, 35], [35, 37, 36]])
9599

100+
###############################################################################
96101
# Rather than create a Triangulation object, can simply pass x, y and triangles
97102
# arrays to tripcolor directly. It would be better to use a Triangulation
98103
# object if the same triangulation was to be used more than once to save
99104
# duplicated calculations.
105+
100106
plt.figure()
101107
plt.gca().set_aspect('equal')
102108
plt.tricontourf(x, y, triangles, z)

0 commit comments

Comments
 (0)
0