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

Skip to content

Commit be4667a

Browse files
committed
Separating examples with multiple plots into separate blocks
1 parent 63744d5 commit be4667a

34 files changed

+217
-61
lines changed

examples/animation/basic_example.py

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

19+
###############################################################################
1920
fig1 = plt.figure()
2021

2122
# Fixing random state for reproducibility
@@ -32,6 +33,7 @@ def update_line(num, data, line):
3233

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

36+
###############################################################################
3537
fig2 = plt.figure()
3638

3739
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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,23 @@
1111
from matplotlib.sankey import Sankey
1212

1313

14+
###############################################################################
1415
# Example 1 -- Mostly defaults
1516
# This demonstrates how to create a simple diagram by implicitly calling the
1617
# Sankey.add() method and by appending finish() to the call to the class.
1718
Sankey(flows=[0.25, 0.15, 0.60, -0.20, -0.15, -0.05, -0.50, -0.10],
1819
labels=['', '', '', 'First', 'Second', 'Third', 'Fourth', 'Fifth'],
1920
orientations=[-1, 1, 0, 1, 1, 1, 0, -1]).finish()
2021
plt.title("The default settings produce a diagram like this.")
22+
###############################################################################
2123
# Notice:
2224
# 1. Axes weren't provided when Sankey() was instantiated, so they were
2325
# created automatically.
2426
# 2. The scale argument wasn't necessary since the data was already
2527
# normalized.
2628
# 3. By default, the lengths of the paths are justified.
2729

30+
###############################################################################
2831
# Example 2
2932
# This demonstrates:
3033
# 1. Setting one path longer than the others
@@ -51,13 +54,15 @@
5154
diagrams = sankey.finish()
5255
diagrams[0].texts[-1].set_color('r')
5356
diagrams[0].text.set_fontweight('bold')
57+
###############################################################################
5458
# Notice:
5559
# 1. Since the sum of the flows is nonzero, the width of the trunk isn't
5660
# uniform. If verbose.level is helpful (in matplotlibrc), a message is
5761
# given in the terminal window.
5862
# 2. The second flow doesn't appear because its value is zero. Again, if
5963
# verbose.level is helpful, a message is given in the terminal window.
6064

65+
###############################################################################
6166
# Example 3
6267
# This demonstrates:
6368
# 1. Connecting two systems
@@ -74,6 +79,7 @@
7479
diagrams = sankey.finish()
7580
diagrams[-1].patch.set_hatch('/')
7681
plt.legend(loc='best')
82+
###############################################################################
7783
# Notice that only one connection is specified, but the systems form a
7884
# circuit since: (1) the lengths of the paths are justified and (2) the
7985
# 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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
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
@@ -37,6 +37,7 @@
3737
plt.title('Simplest default with labels')
3838

3939

40+
###############################################################################
4041
# contour labels can be placed manually by providing list of positions
4142
# (in data coordinate). See ginput_manual_clabel.py for interactive
4243
# placement.
@@ -47,6 +48,7 @@
4748
plt.title('labels at selected locations')
4849

4950

51+
###############################################################################
5052
# You can force all the contours to be the same color.
5153
plt.figure()
5254
CS = plt.contour(X, Y, Z, 6,
@@ -55,6 +57,7 @@
5557
plt.clabel(CS, fontsize=9, inline=1)
5658
plt.title('Single color - negative contours dashed')
5759

60+
###############################################################################
5861
# You can set negative contours to be solid instead of dashed:
5962
matplotlib.rcParams['contour.negative_linestyle'] = 'solid'
6063
plt.figure()
@@ -65,6 +68,7 @@
6568
plt.title('Single color - negative contours solid')
6669

6770

71+
###############################################################################
6872
# And you can manually specify the colors of the contour
6973
plt.figure()
7074
CS = plt.contour(X, Y, Z, 6,
@@ -75,6 +79,7 @@
7579
plt.title('Crazy lines')
7680

7781

82+
###############################################################################
7883
# Or you can use a colormap to specify the colors; the default
7984
# colormap will be used for the contour lines
8085
plt.figure()

examples/images_contours_and_fields/contour_label_demo.py

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

21-
##################################################
21+
###############################################################################
2222
# Define our surface
2323
delta = 0.025
2424
x = np.arange(-3.0, 3.0, delta)
@@ -29,7 +29,7 @@
2929
# difference of Gaussians
3030
Z = 10.0 * (Z2 - Z1)
3131

32-
##################################################
32+
###############################################################################
3333
# Make contour labels using creative float classes
3434
# Follows suggestion of Manuel Metz
3535
plt.figure()
@@ -59,7 +59,7 @@ def __repr__(self):
5959
fmt = '%r %%'
6060
plt.clabel(CS, CS.levels, inline=True, fmt=fmt, fontsize=10)
6161

62-
##################################################
62+
###############################################################################
6363
# Label contours with arbitrary strings using a
6464
# dictionary
6565
plt.figure()
@@ -75,6 +75,7 @@ def __repr__(self):
7575
# Label every other level using strings
7676
plt.clabel(CS, CS.levels[::2], inline=True, fmt=fmt, fontsize=10)
7777

78+
###############################################################################
7879
# Use a Formatter
7980

8081
plt.figure()

examples/images_contours_and_fields/contourf_hatching.py

Lines changed: 2 additions & 2 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,7 +17,7 @@
1817
# we no longer need x and y to be 2 dimensional, so flatten them.
1918
x, y = x.flatten(), y.flatten()
2019

21-
20+
###############################################################################
2221
# ---------------------------------------------
2322
# | Plot #1 |
2423
# ---------------------------------------------
@@ -30,6 +29,7 @@
3029
)
3130
plt.colorbar()
3231

32+
###############################################################################
3333
# ---------------------------------------------
3434
# | Plot #2 |
3535
# ---------------------------------------------

examples/images_contours_and_fields/quiver_demo.py

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

19+
###############################################################################
1920
plt.figure()
2021
plt.title('Arrows scale with plot width, not view')
2122
Q = plt.quiver(X, Y, U, V, units='width')
2223
qk = plt.quiverkey(Q, 0.9, 0.9, 2, r'$2 \frac{m}{s}$', labelpos='E',
2324
coordinates='figure')
2425

26+
###############################################################################
2527
plt.figure()
2628
plt.title("pivot='mid'; every third arrow; units='inches'")
2729
Q = plt.quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3],
@@ -30,6 +32,7 @@
3032
coordinates='figure')
3133
plt.scatter(X[::3, ::3], Y[::3, ::3], color='r', s=5)
3234

35+
###############################################################################
3336
plt.figure()
3437
plt.title("pivot='tip'; scales with x view")
3538
M = np.hypot(U, V)

examples/images_contours_and_fields/tricontour_demo.py

Lines changed: 4 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,6 +37,7 @@
3637
mask = np.where(xmid * xmid + ymid * ymid < min_radius * min_radius, 1, 0)
3738
triang.set_mask(mask)
3839

40+
###############################################################################
3941
# pcolor plot.
4042
plt.figure()
4143
plt.gca().set_aspect('equal')
@@ -44,6 +46,7 @@
4446
plt.tricontour(triang, z, colors='k')
4547
plt.title('Contour plot of Delaunay triangulation')
4648

49+
###############################################################################
4750
# You can specify your own triangulation rather than perform a Delaunay
4851
# triangulation of the points, where each triangle is given by the indices of
4952
# the three points that make up the triangle, ordered in either a clockwise or
@@ -93,6 +96,7 @@
9396
[42, 41, 40], [72, 33, 31], [32, 31, 33], [39, 38, 72], [33, 72, 38],
9497
[33, 38, 34], [37, 35, 38], [34, 38, 35], [35, 37, 36]])
9598

99+
###############################################################################
96100
# Rather than create a Triangulation object, can simply pass x, y and triangles
97101
# arrays to tripcolor directly. It would be better to use a Triangulation
98102
# object if the same triangulation was to be used more than once to save

examples/images_contours_and_fields/tripcolor_demo.py

Lines changed: 5 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,13 +37,15 @@
3637
mask = np.where(xmid * xmid + ymid * ymid < min_radius * min_radius, 1, 0)
3738
triang.set_mask(mask)
3839

40+
###############################################################################
3941
# tripcolor plot.
4042
plt.figure()
4143
plt.gca().set_aspect('equal')
4244
plt.tripcolor(triang, z, shading='flat')
4345
plt.colorbar()
4446
plt.title('tripcolor of Delaunay triangulation, flat shading')
4547

48+
###############################################################################
4649
# Illustrate Gouraud shading.
4750
plt.figure()
4851
plt.gca().set_aspect('equal')
@@ -51,6 +54,7 @@
5154
plt.title('tripcolor of Delaunay triangulation, gouraud shading')
5255

5356

57+
###############################################################################
5458
# You can specify your own triangulation rather than perform a Delaunay
5559
# triangulation of the points, where each triangle is given by the indices of
5660
# the three points that make up the triangle, ordered in either a clockwise or
@@ -103,6 +107,7 @@
103107
zfaces = np.exp(-0.01 * ((xmid - x0) * (xmid - x0) +
104108
(ymid - y0) * (ymid - y0)))
105109

110+
###############################################################################
106111
# Rather than create a Triangulation object, can simply pass x, y and triangles
107112
# arrays to tripcolor directly. It would be better to use a Triangulation
108113
# object if the same triangulation was to be used more than once to save

examples/images_contours_and_fields/triplot_demo.py

Lines changed: 4 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

@@ -35,13 +36,15 @@
3536
mask = np.where(xmid * xmid + ymid * ymid < min_radius * min_radius, 1, 0)
3637
triang.set_mask(mask)
3738

39+
###############################################################################
3840
# Plot the triangulation.
3941
plt.figure()
4042
plt.gca().set_aspect('equal')
4143
plt.triplot(triang, 'bo-', lw=1)
4244
plt.title('triplot of Delaunay triangulation')
4345

4446

47+
###############################################################################
4548
# You can specify your own triangulation rather than perform a Delaunay
4649
# triangulation of the points, where each triangle is given by the indices of
4750
# the three points that make up the triangle, ordered in either a clockwise or
@@ -88,6 +91,7 @@
8891
[42, 41, 40], [72, 33, 31], [32, 31, 33], [39, 38, 72], [33, 72, 38],
8992
[33, 38, 34], [37, 35, 38], [34, 38, 35], [35, 37, 36]])
9093

94+
###############################################################################
9195
# Rather than create a Triangulation object, can simply pass x, y and triangles
9296
# arrays to triplot directly. It would be better to use a Triangulation object
9397
# if the same triangulation was to be used more than once to save duplicated

examples/lines_bars_and_markers/fill.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@
33
Fill plot demo
44
==============
55
6-
First example showcases the most basic fill plot a user can do with matplotlib.
7-
8-
Second example shows a few optional features:
9-
10-
* Multiple curves with a single command.
11-
* Setting the fill color.
12-
* Setting the opacity (alpha value).
6+
Demo fill plot.
137
"""
148
import numpy as np
159
import matplotlib.pyplot as plt
1610

1711
x = np.linspace(0, 1, 500)
1812
y = np.sin(4 * np.pi * x) * np.exp(-5 * x)
1913

14+
###############################################################################
15+
# First, the most basic fill plot a user can make with matplotlib:
16+
2017
fig, ax = plt.subplots()
2118

2219
ax.fill(x, y, zorder=10)
@@ -26,6 +23,13 @@
2623
y1 = np.sin(x)
2724
y2 = np.sin(3 * x)
2825

26+
###############################################################################
27+
# Next, a few more optional features:
28+
#
29+
# * Multiple curves with a single command.
30+
# * Setting the fill color.
31+
# * Setting the opacity (alpha value).
32+
2933
fig, ax = plt.subplots()
3034
ax.fill(x, y1, 'b', x, y2, 'r', alpha=0.3)
3135
plt.show()

examples/lines_bars_and_markers/marker_reference.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ def split_list(a_list):
3030
i_half = len(a_list) // 2
3131
return (a_list[:i_half], a_list[i_half:])
3232

33-
33+
###############################################################################
3434
# Plot all un-filled markers
35-
# --------------------------
3635

3736
fig, axes = plt.subplots(ncols=2)
3837

@@ -53,8 +52,8 @@ def split_list(a_list):
5352
fig.suptitle('un-filled markers', fontsize=14)
5453

5554

55+
###############################################################################
5656
# Plot all filled markers.
57-
# ------------------------
5857

5958
fig, axes = plt.subplots(ncols=2)
6059
for ax, markers in zip(axes, split_list(Line2D.filled_markers)):

0 commit comments

Comments
 (0)