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

Skip to content

Commit 183018c

Browse files
authored
Merge pull request #19703 from jklymak/doc-new-gallery
DOC: new plot gallery
2 parents 10a0e82 + 6e4c4be commit 183018c

31 files changed

+679
-3
lines changed

doc/_templates/layout.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<li><a href="{{ pathto('users/installing') }}">Installation</a></li>
5858
<li><a href="{{ pathto('contents') }}">Documentation</a></li>
5959
<li><a href="{{ pathto('api/index') }}">API</a></li>
60+
<li><a href="{{ pathto('plot_types/index') }}">Plot Types</a></li>
6061
<li><a href="{{ pathto('gallery/index') }}">Examples</a></li>
6162
<li><a href="{{ pathto('tutorials/index') }}">Tutorials</a></li>
6263
<li><a href="{{ pathto('devel/index') }}">Contributing</a></li>

doc/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ def _check_dependencies():
151151

152152
# Sphinx gallery configuration
153153
sphinx_gallery_conf = {
154-
'examples_dirs': ['../examples', '../tutorials'],
154+
'examples_dirs': ['../examples', '../tutorials', '../plot_types'],
155155
'filename_pattern': '^((?!sgskip).)*$',
156-
'gallery_dirs': ['gallery', 'tutorials'],
156+
'gallery_dirs': ['gallery', 'tutorials', 'plot_types'],
157157
'doc_module': ('matplotlib', 'mpl_toolkits'),
158158
'reference_url': {
159159
'matplotlib': None,

doc/sphinxext/gallery_order.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@
2323
'../examples/showcase',
2424
'../tutorials/introductory',
2525
'../tutorials/intermediate',
26-
'../tutorials/advanced']
26+
'../tutorials/advanced',
27+
'../plot_types/basic',
28+
'../plot_types/arrays',
29+
'../plot_types/stats',
30+
'../plot_types/unstructured',
31+
]
2732

2833

2934
class MplExplicitOrder(ExplicitOrder):
@@ -60,6 +65,17 @@ def __call__(self, item):
6065
"color_demo",
6166
# pies
6267
"pie_features", "pie_demo2",
68+
69+
# **Plot Types
70+
# Basic
71+
"plot", "scatter_plot", "bar", "stem", "step", "pie", "fill_between",
72+
# Arrays
73+
"imshow", "pcolormesh", "contourf", "quiver", "streamplot",
74+
# Stats
75+
"hist_plot", "boxplot_plot", "errorbar_plot", "violin",
76+
"barbs", "eventplot", "hist2d", "hexbin",
77+
# Unstructured
78+
"tricontour", "tripcolor", "triplot",
6379
]
6480
explicit_subsection_order = [item + ".py" for item in list_all]
6581

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# from the Matplotlib cheatsheet as used in our gallery:
2+
3+
axes.grid: True
4+
axes.axisbelow: True
5+
6+
figure.figsize: 2, 2
7+
# make it so the axes labels don't show up. Obviously
8+
# not good style for any quantitative analysis:
9+
figure.subplot.left: 0.01
10+
figure.subplot.right: 0.99
11+
figure.subplot.bottom: 0.01
12+
figure.subplot.top: 0.99
13+
14+
xtick.major.size: 0.0
15+
ytick.major.size: 0.0
16+
17+
# colors:
18+
image.cmap : Blues
19+
# axes.prop_cycle: cycler('color', ['FF7F0E', '1F77B4', '2CA02C'])

plot_types/README.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.. _plot_types:
2+
3+
Plot types
4+
==========
5+
6+
This gallery lists many of the plotting commands in Matplotlib,
7+
(but not all of them!).
8+
9+
Note that we have stripped all labels, but they are present by default.
10+
See the `gallery <../gallery/index.html>`_ for many more examples and
11+
the `tutorials page <../tutorials/index.html>`_ for longer examples.

plot_types/arrays/README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. _array_plots:
2+
3+
Plots of arrays and fields
4+
--------------------------
5+
6+
Plotting for arrays of data ``Z(x, y)`` and fields ``U(x, y), V(x, y)``

plot_types/arrays/contourf.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
=====================================
3+
contour[f]([X, Y], Z, [levels=], ...)
4+
=====================================
5+
"""
6+
import matplotlib.pyplot as plt
7+
import numpy as np
8+
9+
plt.style.use('mpl_plot_gallery')
10+
11+
# make data
12+
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
13+
Z = (1 - X/2. + X**5 + Y**3)*np.exp(-X**2-Y**2)
14+
Z = Z - Z.min()
15+
levs = np.linspace(np.min(Z), np.max(Z), 7)
16+
17+
# plot
18+
fig, ax = plt.subplots()
19+
20+
plt.contourf(X, Y, Z, levels=levs)
21+
plt.contour(X, Y, Z, levels=levs, colors="white", linewidths=0.5)
22+
23+
plt.show()

plot_types/arrays/imshow.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
=======================
3+
imshow(Z, [cmap=], ...)
4+
=======================
5+
"""
6+
7+
import matplotlib.pyplot as plt
8+
import numpy as np
9+
10+
plt.style.use('mpl_plot_gallery')
11+
12+
# make data
13+
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
14+
Z = (1 - X/2. + X**5 + Y**3) * np.exp(-X**2 - Y**2)
15+
Z = Z - Z.min()
16+
Z = Z[::16, ::16]
17+
18+
# plot
19+
fig, ax = plt.subplots()
20+
21+
ax.imshow(Z, extent=[0, 8, 0, 8], interpolation="nearest",
22+
cmap=plt.get_cmap('Blues'), vmin=0, vmax=1.6)
23+
24+
ax.set_xticks([])
25+
ax.set_yticks([])
26+
plt.show()

plot_types/arrays/pcolormesh.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
===================================
3+
pcolormesh([X, Y], Z, [cmap=], ...)
4+
===================================
5+
6+
`~.axes.Axes.pcolormesh` is more flexible than `~.axes.Axes.imshow` in that
7+
the x and y vectors need not be equally spaced (indeed they can be skewed).
8+
9+
"""
10+
import matplotlib.pyplot as plt
11+
import numpy as np
12+
13+
plt.style.use('mpl_plot_gallery')
14+
15+
# make full-res data
16+
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
17+
Z = (1 - X/2. + X**5 + Y**3) * np.exp(-X**2 - Y**2)
18+
Z = Z - Z.min()
19+
20+
# sample unevenly in x:
21+
dx = np.sqrt((np.arange(16) - 8)**2) + 6
22+
dx = np.floor(dx / sum(dx) * 255)
23+
xint = np.cumsum(dx).astype('int')
24+
X = X[0, xint]
25+
Y = Y[::8, 0]
26+
Z = Z[::8, :][:, xint]
27+
28+
# plot
29+
fig, ax = plt.subplots()
30+
31+
ax.pcolormesh(X, Y, Z, vmin=0, vmax=1.5, shading='nearest')
32+
33+
plt.show()

plot_types/arrays/quiver.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
=========================
3+
quiver([X, Y], U, V, ...)
4+
=========================
5+
"""
6+
import matplotlib.pyplot as plt
7+
import numpy as np
8+
9+
plt.style.use('mpl_plot_gallery')
10+
11+
# make data
12+
T = np.linspace(0, 2*np.pi, 8)
13+
X, Y = 4 + 1 * np.cos(T), 4 + 1 * np.sin(T)
14+
U, V = 1.5 * np.cos(T), 1.5 * np.sin(T)
15+
16+
# plot
17+
fig, ax = plt.subplots()
18+
19+
plt.quiver(X, Y, U, V, color="C0", angles='xy',
20+
scale_units='xy', scale=0.5, width=.05)
21+
22+
ax.set_xlim(0, 8)
23+
ax.set_xticks(np.arange(1, 8))
24+
ax.set_ylim(0, 8)
25+
ax.set_yticks(np.arange(1, 8))
26+
27+
plt.show()

plot_types/arrays/streamplot.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
========================
3+
streamplot([X, Y], U, V)
4+
========================
5+
"""
6+
import matplotlib.pyplot as plt
7+
import numpy as np
8+
9+
plt.style.use('mpl_plot_gallery')
10+
11+
# make a stream function:
12+
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
13+
Z = (1 - X/2. + X**5 + Y**3) * np.exp(-X**2 - Y**2)
14+
Z = Z - Z.min()
15+
# make U and V out of the streamfunction:
16+
V = np.diff(Z[1:, :], axis=1)
17+
U = -np.diff(Z[:, 1:], axis=0)
18+
19+
# plot:
20+
fig, ax = plt.subplots()
21+
# contour stream function
22+
ax.contour(X, Y, Z, colors='C1', alpha=0.5, zorder=1, linewidths=3)
23+
# plot stream plot
24+
ax.streamplot(X[1:, 1:], Y[1:, 1:], U, V, zorder=2)
25+
26+
plt.show()

plot_types/basic/README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. _basic_plots:
2+
3+
Basic
4+
-----
5+
6+
Basic plot types, usually x versus y.

plot_types/basic/bar.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
======================
3+
bar[h](x, height, ...)
4+
======================
5+
"""
6+
import matplotlib.pyplot as plt
7+
import numpy as np
8+
plt.style.use('mpl_plot_gallery')
9+
10+
# make data:
11+
np.random.seed(3)
12+
X = 0.5 + np.arange(8)
13+
Y = np.random.uniform(2, 7, len(X))
14+
15+
# plot
16+
fig, ax = plt.subplots()
17+
18+
ax.bar(X, Y, width=1, edgecolor="white", linewidth=0.7)
19+
20+
ax.set_xlim(0, 8)
21+
ax.set_xticks(np.arange(1, 8))
22+
ax.set_ylim(0, 8)
23+
ax.set_yticks(np.arange(1, 8))
24+
plt.show()

plot_types/basic/pie.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
====================
3+
pie(X, explode, ...)
4+
====================
5+
"""
6+
import matplotlib as mpl
7+
import matplotlib.pyplot as plt
8+
import numpy as np
9+
10+
plt.style.use('mpl_plot_gallery')
11+
12+
13+
# make data
14+
X = [1, 2, 3, 4]
15+
colors = np.zeros((len(X), 4))
16+
colors[:] = mpl.colors.to_rgba("C0")
17+
colors[:, 3] = np.linspace(0.25, 0.75, len(X))
18+
19+
# plot
20+
fig, ax = plt.subplots()
21+
ax.pie(X, colors=["white"]*len(X), radius=3, center=(4, 4),
22+
wedgeprops={"linewidth": 1, "edgecolor": "white"}, frame=True)
23+
ax.pie(X, colors=colors, radius=3, center=(4, 4),
24+
wedgeprops={"linewidth": 1, "edgecolor": "white"}, frame=True)
25+
26+
ax.set_xlim(0, 8)
27+
ax.set_xticks(np.arange(1, 8))
28+
ax.set_ylim(0, 8)
29+
ax.set_yticks(np.arange(1, 8))
30+
31+
plt.show()

plot_types/basic/plot.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
======================
3+
plot([X], Y, [fmt]...)
4+
======================
5+
"""
6+
7+
import matplotlib.pyplot as plt
8+
import numpy as np
9+
10+
plt.style.use('mpl_plot_gallery')
11+
12+
# make data
13+
X = np.linspace(0, 10, 100)
14+
Y = 4 + 2 * np.sin(2 * X)
15+
16+
# plot
17+
fig, ax = plt.subplots()
18+
19+
ax.plot(X, Y, linewidth=2.0)
20+
21+
ax.set_xlim(0, 8)
22+
ax.set_xticks(np.arange(1, 8))
23+
ax.set_ylim(0, 8)
24+
ax.set_yticks(np.arange(1, 8))
25+
plt.show()

plot_types/basic/scatter_plot.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
==================
3+
scatter(X, Y, ...)
4+
==================
5+
"""
6+
import matplotlib.pyplot as plt
7+
import numpy as np
8+
9+
plt.style.use('mpl_plot_gallery')
10+
11+
# make the data
12+
np.random.seed(3)
13+
X = 4 + np.random.normal(0, 2, 24)
14+
Y = 4 + np.random.normal(0, 2, len(X))
15+
# size and color:
16+
S = np.random.uniform(15, 80, len(X))
17+
18+
# plot
19+
fig, ax = plt.subplots()
20+
21+
ax.scatter(X, Y, s=S, c=-S, cmap=plt.get_cmap('Blues'), vmin=-100, vmax=0)
22+
23+
ax.set_xlim(0, 8)
24+
ax.set_xticks(np.arange(1, 8))
25+
ax.set_ylim(0, 8)
26+
ax.set_yticks(np.arange(1, 8))
27+
plt.show()

plot_types/basic/stem.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
=================
3+
stem([x], y, ...)
4+
=================
5+
"""
6+
import matplotlib.pyplot as plt
7+
import numpy as np
8+
9+
plt.style.use('mpl_plot_gallery')
10+
11+
# make data
12+
np.random.seed(3)
13+
X = 0.5 + np.arange(8)
14+
Y = np.random.uniform(2, 7, len(X))
15+
16+
# plot
17+
fig, ax = plt.subplots()
18+
19+
ax.stem(X, Y, bottom=0, linefmt="-", markerfmt="d")
20+
21+
ax.set_xlim(0, 8)
22+
ax.set_xticks(np.arange(1, 8))
23+
ax.set_ylim(0, 8)
24+
ax.set_yticks(np.arange(1, 8))
25+
plt.show()

0 commit comments

Comments
 (0)