Skip to content

Commit ceff2a4

Browse files
committed
Add docs for 3.7.5
1 parent c489bc7 commit ceff2a4

File tree

8,502 files changed

+4362112
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

8,502 files changed

+4362112
-0
lines changed

3.7.5/Matplotlib.pdf

55 MB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"\n# Plotting multiple lines with a LineCollection\n\nMatplotlib can efficiently draw multiple lines at once using a\n`~.LineCollection`, as showcased below.\n"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": null,
13+
"metadata": {
14+
"collapsed": false
15+
},
16+
"outputs": [],
17+
"source": [
18+
"import matplotlib.pyplot as plt\nfrom matplotlib.collections import LineCollection\n\nimport numpy as np\n\n\nx = np.arange(100)\n# Here are many sets of y to plot vs. x\nys = x[:50, np.newaxis] + x[np.newaxis, :]\n\nsegs = np.zeros((50, 100, 2))\nsegs[:, :, 1] = ys\nsegs[:, :, 0] = x\n\n# Mask some values to test masked array support:\nsegs = np.ma.masked_where((segs > 50) & (segs < 60), segs)\n\n# We need to set the plot limits, they will not autoscale\nfig, ax = plt.subplots()\nax.set_xlim(x.min(), x.max())\nax.set_ylim(ys.min(), ys.max())\n\n# *colors* is sequence of rgba tuples.\n# *linestyle* is a string or dash tuple. Legal string values are\n# solid|dashed|dashdot|dotted. The dash tuple is (offset, onoffseq) where\n# onoffseq is an even length tuple of on and off ink in points. If linestyle\n# is omitted, 'solid' is used.\n# See `matplotlib.collections.LineCollection` for more information.\ncolors = plt.rcParams['axes.prop_cycle'].by_key()['color']\n\nline_segments = LineCollection(segs, linewidths=(0.5, 1, 1.5, 2),\n colors=colors, linestyle='solid')\nax.add_collection(line_segments)\nax.set_title('Line collection with masked arrays')\nplt.show()"
19+
]
20+
},
21+
{
22+
"cell_type": "markdown",
23+
"metadata": {},
24+
"source": [
25+
"In the following example, instead of passing a list of colors\n(``colors=colors``), we pass an array of values (``array=x``) that get\ncolormapped.\n\n"
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": null,
31+
"metadata": {
32+
"collapsed": false
33+
},
34+
"outputs": [],
35+
"source": [
36+
"N = 50\nx = np.arange(N)\nys = [x + i for i in x] # Many sets of y to plot vs. x\nsegs = [np.column_stack([x, y]) for y in ys]\n\nfig, ax = plt.subplots()\nax.set_xlim(np.min(x), np.max(x))\nax.set_ylim(np.min(ys), np.max(ys))\n\nline_segments = LineCollection(segs, array=x,\n linewidths=(0.5, 1, 1.5, 2),\n linestyles='solid')\nax.add_collection(line_segments)\naxcb = fig.colorbar(line_segments)\naxcb.set_label('Line Number')\nax.set_title('Line Collection with mapped colors')\nplt.sci(line_segments) # This allows interactive changing of the colormap.\nplt.show()"
37+
]
38+
},
39+
{
40+
"cell_type": "markdown",
41+
"metadata": {},
42+
"source": [
43+
".. admonition:: References\n\n The use of the following functions, methods, classes and modules is shown\n in this example:\n\n - `matplotlib.collections`\n - `matplotlib.collections.LineCollection`\n - `matplotlib.cm.ScalarMappable.set_array`\n - `matplotlib.axes.Axes.add_collection`\n - `matplotlib.figure.Figure.colorbar` / `matplotlib.pyplot.colorbar`\n - `matplotlib.pyplot.sci`\n\n"
44+
]
45+
}
46+
],
47+
"metadata": {
48+
"kernelspec": {
49+
"display_name": "Python 3",
50+
"language": "python",
51+
"name": "python3"
52+
},
53+
"language_info": {
54+
"codemirror_mode": {
55+
"name": "ipython",
56+
"version": 3
57+
},
58+
"file_extension": ".py",
59+
"mimetype": "text/x-python",
60+
"name": "python",
61+
"nbconvert_exporter": "python",
62+
"pygments_lexer": "ipython3",
63+
"version": "3.12.1"
64+
}
65+
},
66+
"nbformat": 4,
67+
"nbformat_minor": 0
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
x = np.linspace(1., 3., 10)
2+
y = x**3
3+
4+
fig, ax = plt.subplots()
5+
ax.plot(x, y, linestyle='--', color='orange', gapcolor='blue',
6+
linewidth=3, label='a striped line')
7+
ax.legend()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
==========
3+
Hyperlinks
4+
==========
5+
6+
This example demonstrates how to set a hyperlinks on various kinds of elements.
7+
8+
This currently only works with the SVG backend.
9+
10+
"""
11+
12+
13+
import numpy as np
14+
import matplotlib.cm as cm
15+
import matplotlib.pyplot as plt
16+
17+
###############################################################################
18+
19+
fig = plt.figure()
20+
s = plt.scatter([1, 2, 3], [4, 5, 6])
21+
s.set_urls(['https://www.bbc.com/news', 'https://www.google.com/', None])
22+
fig.savefig('scatter.svg')
23+
24+
###############################################################################
25+
26+
fig = plt.figure()
27+
delta = 0.025
28+
x = y = np.arange(-3.0, 3.0, delta)
29+
X, Y = np.meshgrid(x, y)
30+
Z1 = np.exp(-X**2 - Y**2)
31+
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
32+
Z = (Z1 - Z2) * 2
33+
34+
im = plt.imshow(Z, interpolation='bilinear', cmap=cm.gray,
35+
origin='lower', extent=[-3, 3, -3, 3])
36+
37+
im.set_url('https://www.google.com/')
38+
fig.savefig('image.svg')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
================
3+
pyplot animation
4+
================
5+
6+
Generating an animation by calling `~.pyplot.pause` between plotting commands.
7+
8+
The method shown here is only suitable for simple, low-performance use. For
9+
more demanding applications, look at the :mod:`.animation` module and the
10+
examples that use it.
11+
12+
Note that calling `time.sleep` instead of `~.pyplot.pause` would *not* work.
13+
14+
Output generated via `matplotlib.animation.Animation.to_jshtml`.
15+
"""
16+
17+
import matplotlib.pyplot as plt
18+
import numpy as np
19+
20+
np.random.seed(19680801)
21+
data = np.random.random((50, 50, 50))
22+
23+
fig, ax = plt.subplots()
24+
25+
for i, img in enumerate(data):
26+
ax.clear()
27+
ax.imshow(img)
28+
ax.set_title(f"frame {i}")
29+
# Note that using time.sleep does *not* work here!
30+
plt.pause(0.1)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"\n# Hatch style reference\n\nHatches can be added to most polygons in Matplotlib, including `~.Axes.bar`,\n`~.Axes.fill_between`, `~.Axes.contourf`, and children of `~.patches.Polygon`.\nThey are currently supported in the PS, PDF, SVG, OSX, and Agg backends. The WX\nand Cairo backends do not currently support hatching.\n\nSee also :doc:`/gallery/images_contours_and_fields/contourf_hatching` for\nan example using `~.Axes.contourf`, and\n:doc:`/gallery/shapes_and_collections/hatch_demo` for more usage examples.\n"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": null,
13+
"metadata": {
14+
"collapsed": false
15+
},
16+
"outputs": [],
17+
"source": [
18+
"import matplotlib.pyplot as plt\nfrom matplotlib.patches import Rectangle\n\nfig, axs = plt.subplots(2, 5, layout='constrained', figsize=(6.4, 3.2))\n\nhatches = ['/', '\\\\', '|', '-', '+', 'x', 'o', 'O', '.', '*']\n\n\ndef hatches_plot(ax, h):\n ax.add_patch(Rectangle((0, 0), 2, 2, fill=False, hatch=h))\n ax.text(1, -0.5, f\"' {h} '\", size=15, ha=\"center\")\n ax.axis('equal')\n ax.axis('off')\n\nfor ax, h in zip(axs.flat, hatches):\n hatches_plot(ax, h)"
19+
]
20+
},
21+
{
22+
"cell_type": "markdown",
23+
"metadata": {},
24+
"source": [
25+
"Hatching patterns can be repeated to increase the density.\n\n"
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": null,
31+
"metadata": {
32+
"collapsed": false
33+
},
34+
"outputs": [],
35+
"source": [
36+
"fig, axs = plt.subplots(2, 5, layout='constrained', figsize=(6.4, 3.2))\n\nhatches = ['//', '\\\\\\\\', '||', '--', '++', 'xx', 'oo', 'OO', '..', '**']\n\nfor ax, h in zip(axs.flat, hatches):\n hatches_plot(ax, h)"
37+
]
38+
},
39+
{
40+
"cell_type": "markdown",
41+
"metadata": {},
42+
"source": [
43+
"Hatching patterns can be combined to create additional patterns.\n\n"
44+
]
45+
},
46+
{
47+
"cell_type": "code",
48+
"execution_count": null,
49+
"metadata": {
50+
"collapsed": false
51+
},
52+
"outputs": [],
53+
"source": [
54+
"fig, axs = plt.subplots(2, 5, layout='constrained', figsize=(6.4, 3.2))\n\nhatches = ['/o', '\\\\|', '|*', '-\\\\', '+o', 'x*', 'o-', 'O|', 'O.', '*-']\n\nfor ax, h in zip(axs.flat, hatches):\n hatches_plot(ax, h)"
55+
]
56+
},
57+
{
58+
"cell_type": "markdown",
59+
"metadata": {},
60+
"source": [
61+
".. admonition:: References\n\n The use of the following functions, methods, classes and modules is shown\n in this example:\n\n - `matplotlib.patches`\n - `matplotlib.patches.Rectangle`\n - `matplotlib.axes.Axes.add_patch`\n - `matplotlib.axes.Axes.text`\n\n"
62+
]
63+
}
64+
],
65+
"metadata": {
66+
"kernelspec": {
67+
"display_name": "Python 3",
68+
"language": "python",
69+
"name": "python3"
70+
},
71+
"language_info": {
72+
"codemirror_mode": {
73+
"name": "ipython",
74+
"version": 3
75+
},
76+
"file_extension": ".py",
77+
"mimetype": "text/x-python",
78+
"name": "python",
79+
"nbconvert_exporter": "python",
80+
"pygments_lexer": "ipython3",
81+
"version": "3.12.1"
82+
}
83+
},
84+
"nbformat": 4,
85+
"nbformat_minor": 0
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
"""
2+
===============
3+
Tricontour Demo
4+
===============
5+
6+
Contour plots of unstructured triangular grids.
7+
"""
8+
import matplotlib.pyplot as plt
9+
import matplotlib.tri as tri
10+
import numpy as np
11+
12+
###############################################################################
13+
# Creating a Triangulation without specifying the triangles results in the
14+
# Delaunay triangulation of the points.
15+
16+
# First create the x and y coordinates of the points.
17+
n_angles = 48
18+
n_radii = 8
19+
min_radius = 0.25
20+
radii = np.linspace(min_radius, 0.95, n_radii)
21+
22+
angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False)
23+
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
24+
angles[:, 1::2] += np.pi / n_angles
25+
26+
x = (radii * np.cos(angles)).flatten()
27+
y = (radii * np.sin(angles)).flatten()
28+
z = (np.cos(radii) * np.cos(3 * angles)).flatten()
29+
30+
# Create the Triangulation; no triangles so Delaunay triangulation created.
31+
triang = tri.Triangulation(x, y)
32+
33+
# Mask off unwanted triangles.
34+
triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1),
35+
y[triang.triangles].mean(axis=1))
36+
< min_radius)
37+
38+
###############################################################################
39+
# pcolor plot.
40+
41+
fig1, ax1 = plt.subplots()
42+
ax1.set_aspect('equal')
43+
tcf = ax1.tricontourf(triang, z)
44+
fig1.colorbar(tcf)
45+
ax1.tricontour(triang, z, colors='k')
46+
ax1.set_title('Contour plot of Delaunay triangulation')
47+
48+
49+
###############################################################################
50+
# You could also specify hatching patterns along with different cmaps.
51+
52+
fig2, ax2 = plt.subplots()
53+
ax2.set_aspect("equal")
54+
tcf = ax2.tricontourf(
55+
triang,
56+
z,
57+
hatches=["*", "-", "/", "//", "\\", None],
58+
cmap="cividis"
59+
)
60+
fig2.colorbar(tcf)
61+
ax2.tricontour(triang, z, linestyles="solid", colors="k", linewidths=2.0)
62+
ax2.set_title("Hatched Contour plot of Delaunay triangulation")
63+
64+
###############################################################################
65+
# You could also generate hatching patterns labeled with no color.
66+
67+
fig3, ax3 = plt.subplots()
68+
n_levels = 7
69+
tcf = ax3.tricontourf(
70+
triang,
71+
z,
72+
n_levels,
73+
colors="none",
74+
hatches=[".", "/", "\\", None, "\\\\", "*"],
75+
)
76+
ax3.tricontour(triang, z, n_levels, colors="black", linestyles="-")
77+
78+
79+
# create a legend for the contour set
80+
artists, labels = tcf.legend_elements(str_format="{:2.1f}".format)
81+
ax3.legend(artists, labels, handleheight=2, framealpha=1)
82+
83+
###############################################################################
84+
# You can specify your own triangulation rather than perform a Delaunay
85+
# triangulation of the points, where each triangle is given by the indices of
86+
# the three points that make up the triangle, ordered in either a clockwise or
87+
# anticlockwise manner.
88+
89+
xy = np.asarray([
90+
[-0.101, 0.872], [-0.080, 0.883], [-0.069, 0.888], [-0.054, 0.890],
91+
[-0.045, 0.897], [-0.057, 0.895], [-0.073, 0.900], [-0.087, 0.898],
92+
[-0.090, 0.904], [-0.069, 0.907], [-0.069, 0.921], [-0.080, 0.919],
93+
[-0.073, 0.928], [-0.052, 0.930], [-0.048, 0.942], [-0.062, 0.949],
94+
[-0.054, 0.958], [-0.069, 0.954], [-0.087, 0.952], [-0.087, 0.959],
95+
[-0.080, 0.966], [-0.085, 0.973], [-0.087, 0.965], [-0.097, 0.965],
96+
[-0.097, 0.975], [-0.092, 0.984], [-0.101, 0.980], [-0.108, 0.980],
97+
[-0.104, 0.987], [-0.102, 0.993], [-0.115, 1.001], [-0.099, 0.996],
98+
[-0.101, 1.007], [-0.090, 1.010], [-0.087, 1.021], [-0.069, 1.021],
99+
[-0.052, 1.022], [-0.052, 1.017], [-0.069, 1.010], [-0.064, 1.005],
100+
[-0.048, 1.005], [-0.031, 1.005], [-0.031, 0.996], [-0.040, 0.987],
101+
[-0.045, 0.980], [-0.052, 0.975], [-0.040, 0.973], [-0.026, 0.968],
102+
[-0.020, 0.954], [-0.006, 0.947], [ 0.003, 0.935], [ 0.006, 0.926],
103+
[ 0.005, 0.921], [ 0.022, 0.923], [ 0.033, 0.912], [ 0.029, 0.905],
104+
[ 0.017, 0.900], [ 0.012, 0.895], [ 0.027, 0.893], [ 0.019, 0.886],
105+
[ 0.001, 0.883], [-0.012, 0.884], [-0.029, 0.883], [-0.038, 0.879],
106+
[-0.057, 0.881], [-0.062, 0.876], [-0.078, 0.876], [-0.087, 0.872],
107+
[-0.030, 0.907], [-0.007, 0.905], [-0.057, 0.916], [-0.025, 0.933],
108+
[-0.077, 0.990], [-0.059, 0.993]])
109+
x = np.degrees(xy[:, 0])
110+
y = np.degrees(xy[:, 1])
111+
x0 = -5
112+
y0 = 52
113+
z = np.exp(-0.01 * ((x - x0) ** 2 + (y - y0) ** 2))
114+
115+
triangles = np.asarray([
116+
[67, 66, 1], [65, 2, 66], [ 1, 66, 2], [64, 2, 65], [63, 3, 64],
117+
[60, 59, 57], [ 2, 64, 3], [ 3, 63, 4], [ 0, 67, 1], [62, 4, 63],
118+
[57, 59, 56], [59, 58, 56], [61, 60, 69], [57, 69, 60], [ 4, 62, 68],
119+
[ 6, 5, 9], [61, 68, 62], [69, 68, 61], [ 9, 5, 70], [ 6, 8, 7],
120+
[ 4, 70, 5], [ 8, 6, 9], [56, 69, 57], [69, 56, 52], [70, 10, 9],
121+
[54, 53, 55], [56, 55, 53], [68, 70, 4], [52, 56, 53], [11, 10, 12],
122+
[69, 71, 68], [68, 13, 70], [10, 70, 13], [51, 50, 52], [13, 68, 71],
123+
[52, 71, 69], [12, 10, 13], [71, 52, 50], [71, 14, 13], [50, 49, 71],
124+
[49, 48, 71], [14, 16, 15], [14, 71, 48], [17, 19, 18], [17, 20, 19],
125+
[48, 16, 14], [48, 47, 16], [47, 46, 16], [16, 46, 45], [23, 22, 24],
126+
[21, 24, 22], [17, 16, 45], [20, 17, 45], [21, 25, 24], [27, 26, 28],
127+
[20, 72, 21], [25, 21, 72], [45, 72, 20], [25, 28, 26], [44, 73, 45],
128+
[72, 45, 73], [28, 25, 29], [29, 25, 31], [43, 73, 44], [73, 43, 40],
129+
[72, 73, 39], [72, 31, 25], [42, 40, 43], [31, 30, 29], [39, 73, 40],
130+
[42, 41, 40], [72, 33, 31], [32, 31, 33], [39, 38, 72], [33, 72, 38],
131+
[33, 38, 34], [37, 35, 38], [34, 38, 35], [35, 37, 36]])
132+
133+
###############################################################################
134+
# Rather than create a Triangulation object, can simply pass x, y and triangles
135+
# arrays to tripcolor directly. It would be better to use a Triangulation
136+
# object if the same triangulation was to be used more than once to save
137+
# duplicated calculations.
138+
139+
fig4, ax4 = plt.subplots()
140+
ax4.set_aspect('equal')
141+
tcf = ax4.tricontourf(x, y, triangles, z)
142+
fig4.colorbar(tcf)
143+
ax4.set_title('Contour plot of user-specified triangulation')
144+
ax4.set_xlabel('Longitude (degrees)')
145+
ax4.set_ylabel('Latitude (degrees)')
146+
147+
plt.show()
148+
149+
#############################################################################
150+
#
151+
# .. admonition:: References
152+
#
153+
# The use of the following functions, methods, classes and modules is shown
154+
# in this example:
155+
#
156+
# - `matplotlib.axes.Axes.tricontourf` / `matplotlib.pyplot.tricontourf`
157+
# - `matplotlib.tri.Triangulation`
158+
# - `matplotlib.figure.Figure.colorbar` / `matplotlib.pyplot.colorbar`
159+
# - `matplotlib.axes.Axes.legend` / `matplotlib.pyplot.legend`
160+
# - `matplotlib.contour.ContourSet.legend_elements`

0 commit comments

Comments
 (0)