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

Skip to content

Commit 8683873

Browse files
committed
New doc gallery
1 parent bd7df78 commit 8683873

31 files changed

+772
-2
lines changed

doc/_templates/layout.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
<ul>
5757
<li><a href="{{ pathto('users/installing') }}">Installation</a></li>
5858
<li><a href="{{ pathto('contents') }}">Documentation</a></li>
59+
<li><a href="{{ pathto('plot_types/index') }}">Plot Types</a></li>
5960
<li><a href="{{ pathto('gallery/index') }}">Examples</a></li>
6061
<li><a href="{{ pathto('tutorials/index') }}">Tutorials</a></li>
6162
<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', '../basic_plots'],
155155
'filename_pattern': '^((?!sgskip).)*$',
156-
'gallery_dirs': ['gallery', 'tutorials'],
156+
'gallery_dirs': ['gallery', 'tutorials', 'basic_plots'],
157157
'doc_module': ('matplotlib', 'mpl_toolkits'),
158158
'reference_url': {
159159
'matplotlib': None,

plot_types/A_basic/README.txt

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/A_basic/a_plot.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
======================
3+
plot([X], Y, [fmt]...)
4+
======================
5+
"""
6+
7+
import matplotlib.pyplot as plt
8+
import numpy as np
9+
10+
11+
fig = plt.figure(figsize=(2, 2))
12+
plt.rcParams['axes.linewidth'] = 1.5
13+
plt.rcParams['xtick.major.size'] = 0.0
14+
plt.rcParams['ytick.major.size'] = 0.0
15+
d = 0.01
16+
ax = fig.add_axes([d, d, 1-2*d, 1-2*d])
17+
18+
# make data
19+
X = np.linspace(0, 10, 100)
20+
Y = 4 + 2 * np.sin(2 * X)
21+
ax.plot(X, Y, color="C1", linewidth=2.0)
22+
23+
# plot
24+
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
25+
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
26+
ax.grid(linewidth=0.75)
27+
28+
plt.show()

plot_types/A_basic/b_scatter.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
==================
3+
scatter(X, Y, ...)
4+
==================
5+
"""
6+
7+
import matplotlib.pyplot as plt
8+
import numpy as np
9+
10+
fig = plt.figure(figsize=(2, 2))
11+
plt.rcParams['axes.linewidth'] = 1.5
12+
plt.rcParams['xtick.major.size'] = 0.0
13+
plt.rcParams['ytick.major.size'] = 0.0
14+
d = 0.01
15+
ax = fig.add_axes([d, d, 1-2*d, 1-2*d])
16+
17+
# make the data
18+
np.random.seed(3)
19+
X = 4+np.random.normal(0, 1.25, 24)
20+
Y = 4+np.random.normal(0, 1.25, len(X))
21+
22+
ax.scatter(X, Y, 20, zorder=10,
23+
edgecolor="none", facecolor="C1", linewidth=0.25)
24+
25+
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
26+
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
27+
ax.grid(linewidth=0.7)
28+
plt.show()

plot_types/A_basic/c_bar.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
======================
3+
bar[h](x, height, ...)
4+
======================
5+
"""
6+
import matplotlib.pyplot as plt
7+
import numpy as np
8+
9+
fig = plt.figure(figsize=(2, 2))
10+
plt.rcParams['axes.linewidth'] = 1.5
11+
plt.rcParams['xtick.major.size'] = 0.0
12+
plt.rcParams['ytick.major.size'] = 0.0
13+
d = 0.01
14+
ax = fig.add_axes([d, d, 1-2*d, 1-2*d])
15+
16+
# make data
17+
np.random.seed(3)
18+
X = 0.5 + np.arange(8)
19+
Y = np.random.uniform(2, 7, len(X))
20+
21+
# plot
22+
ax.bar(X, Y, bottom=0, width=1, edgecolor="white",
23+
facecolor="C1", linewidth=0.7)
24+
25+
ax.set_axisbelow(True)
26+
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
27+
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
28+
ax.grid(linewidth=0.7)
29+
plt.show()

plot_types/A_basic/d_stem.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
=================
3+
stem([x], y, ...)
4+
=================
5+
"""
6+
import matplotlib.pyplot as plt
7+
import numpy as np
8+
9+
fig = plt.figure(figsize=(2, 2))
10+
plt.rcParams['axes.linewidth'] = 1.5
11+
plt.rcParams['xtick.major.size'] = 0.0
12+
plt.rcParams['ytick.major.size'] = 0.0
13+
d = 0.01
14+
ax = fig.add_axes([d, d, 1-2*d, 1-2*d])
15+
16+
# make data
17+
np.random.seed(3)
18+
X = 0.5 + np.arange(8)
19+
Y = np.random.uniform(2, 7, len(X))
20+
21+
# plot
22+
ax.stem(X, Y, bottom=0, linefmt="C1-", markerfmt="C1d")
23+
24+
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
25+
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
26+
ax.grid(linewidth=0.7)
27+
plt.show()

plot_types/A_basic/e_step.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
=====================
3+
step(x, y, where=...)
4+
=====================
5+
"""
6+
import matplotlib.pyplot as plt
7+
import numpy as np
8+
9+
fig = plt.figure(figsize=(2, 2))
10+
plt.rcParams['axes.linewidth'] = 1.5
11+
plt.rcParams['xtick.major.size'] = 0.0
12+
plt.rcParams['ytick.major.size'] = 0.0
13+
d = 0.01
14+
ax = fig.add_axes([d, d, 1-2*d, 1-2*d])
15+
16+
# make data
17+
np.random.seed(3)
18+
X = 0.5 + np.arange(8)
19+
Y = np.random.uniform(2, 7, len(X))
20+
21+
# plot
22+
ax.step(X, Y, color="C1", linewidth=2.5)
23+
24+
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
25+
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
26+
ax.grid(linewidth=0.7)
27+
plt.show()

plot_types/A_basic/f_pie.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
fig = plt.figure(figsize=(2, 2))
11+
plt.rcParams['axes.linewidth'] = 1.5
12+
plt.rcParams['xtick.major.size'] = 0.0
13+
plt.rcParams['ytick.major.size'] = 0.0
14+
d = 0.01
15+
ax = fig.add_axes([d, d, 1-2*d, 1-2*d])
16+
17+
# make data
18+
X = [1, 2, 3, 4]
19+
colors = np.zeros((len(X), 4))
20+
colors[:] = mpl.colors.to_rgba("C1")
21+
colors[:, 3] = np.linspace(0.25, 0.75, len(X))
22+
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
23+
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
24+
ax.grid(linewidth=0.25, color="0.75")
25+
26+
# plot
27+
ax.pie(X, colors=["white"]*len(X), radius=3, center=(4, 4),
28+
wedgeprops={"linewidth": 1, "edgecolor": "white"}, frame=True)
29+
ax.pie(X, colors=colors, radius=3, center=(4, 4),
30+
wedgeprops={"linewidth": 1, "edgecolor": "white"}, frame=True)
31+
32+
plt.show()

plot_types/A_basic/g_fill_between.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
=================================
3+
fill[_between][x](X, Y1, Y2, ...)
4+
=================================
5+
"""
6+
import matplotlib.pyplot as plt
7+
import numpy as np
8+
9+
fig = plt.figure(figsize=(2, 2))
10+
plt.rcParams['axes.linewidth'] = 1.5
11+
plt.rcParams['xtick.major.size'] = 0.0
12+
plt.rcParams['ytick.major.size'] = 0.0
13+
d = 0.01
14+
ax = fig.add_axes([d, d, 1-2*d, 1-2*d])
15+
16+
# make data
17+
np.random.seed(1)
18+
X = np.linspace(0, 8, 16)
19+
Y1 = 3 + 4*X/8 + np.random.uniform(0.0, 0.5, len(X))
20+
Y2 = 1 + 2*X/8 + np.random.uniform(0.0, 0.5, len(X))
21+
22+
# plot
23+
plt.fill_between(X, Y1, Y2, color="C1", alpha=.5, linewidth=0)
24+
plt.plot(X, (Y1+Y2)/2, color="C1", linewidth=2.5)
25+
26+
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
27+
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
28+
ax.set_axisbelow(True)
29+
ax.grid(linewidth=0.7, color="0.75")
30+
31+
plt.show()

plot_types/B_arrays/README.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. _array_plots:
2+
3+
Arrays and Fields
4+
=================
5+
6+
Ways to plot a 2-dimensional array ``Z``, or a field of ``(U, V)`` pairs.

plot_types/B_arrays/a_imshow.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
=======================
3+
imshow(Z, [cmap=], ...)
4+
=======================
5+
6+
"""
7+
8+
import matplotlib.pyplot as plt
9+
import numpy as np
10+
11+
fig = plt.figure(figsize=(2, 2))
12+
plt.rcParams['axes.linewidth'] = 1.5
13+
plt.rcParams['xtick.major.size'] = 0.0
14+
plt.rcParams['ytick.major.size'] = 0.0
15+
d = 0.01
16+
ax = fig.add_axes([d, d, 1-2*d, 1-2*d])
17+
18+
# Make data
19+
Z = np.random.uniform(0.1, 0.9, (8, 8))
20+
21+
ax.imshow(Z, extent=[0, 8, 0, 8], interpolation="nearest",
22+
cmap=plt.get_cmap('Oranges'), vmin=0, vmax=1)
23+
24+
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
25+
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
26+
27+
plt.show()

plot_types/B_arrays/b_pcolormesh.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
===================================
3+
pcolormesh([X, Y], Z, [cmap=], ...)
4+
===================================
5+
6+
"""
7+
import matplotlib.pyplot as plt
8+
import numpy as np
9+
10+
fig = plt.figure(figsize=(2, 2))
11+
plt.rcParams['axes.linewidth'] = 1.5
12+
plt.rcParams['xtick.major.size'] = 0.0
13+
plt.rcParams['ytick.major.size'] = 0.0
14+
d = 0.01
15+
ax = fig.add_axes([d, d, 1-2*d, 1-2*d])
16+
17+
# make data:
18+
np.random.seed(3)
19+
Z = np.random.uniform(0.1, 1.0, (8, 8))
20+
x = np.array([0, 0.5, 1.5, 3, 5.2, 6.3, 7.2, 7.5, 8])
21+
y = 1.2**np.arange(0, 9)
22+
23+
# plot:
24+
ax.pcolormesh(x, y, Z, cmap=plt.get_cmap('Oranges'), vmin=0, vmax=1.1)
25+
26+
# set limits
27+
ax.set_ylim(1, np.max(y))
28+
ax.set_xlim(np.min(x), np.max(x))
29+
30+
plt.show()

plot_types/B_arrays/c_contourf.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
=====================================
3+
contour[f]([X, Y], Z, [levels=], ...)
4+
=====================================
5+
"""
6+
import matplotlib.pyplot as plt
7+
import numpy as np
8+
9+
fig = plt.figure(figsize=(2, 2))
10+
plt.rcParams['axes.linewidth'] = 1.5
11+
plt.rcParams['xtick.major.size'] = 0.0
12+
plt.rcParams['ytick.major.size'] = 0.0
13+
d = 0.01
14+
ax = fig.add_axes([d, d, 1-2*d, 1-2*d])
15+
16+
17+
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
18+
Z = (1 - X/2. + X**5 + Y**3)*np.exp(-X**2-Y**2)
19+
Z = Z - Z.min()
20+
levs = np.linspace(np.min(Z), np.max(Z), 7)
21+
plt.contourf(X, Y, Z, levels=levs, cmap=plt.get_cmap('Oranges'))
22+
plt.contour(X, Y, Z, levels=levs, colors="white", linewidths=0.5)
23+
24+
plt.show()

plot_types/B_arrays/d_quiver.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
=========================
3+
quiver([X, Y], U, V, ...)
4+
=========================
5+
"""
6+
import matplotlib.pyplot as plt
7+
import numpy as np
8+
9+
fig = plt.figure(figsize=(2, 2))
10+
plt.rcParams['axes.linewidth'] = 1.5
11+
plt.rcParams['xtick.major.size'] = 0.0
12+
plt.rcParams['ytick.major.size'] = 0.0
13+
d = 0.01
14+
ax = fig.add_axes([d, d, 1-2*d, 1-2*d])
15+
16+
# make data
17+
T = np.linspace(0, 2*np.pi, 8)
18+
X, Y = 4 + 1 * np.cos(T), 4 + 1 * np.sin(T)
19+
U, V = 1.5 * np.cos(T), 1.5 * np.sin(T)
20+
21+
# plot
22+
plt.quiver(X, Y, U, V, color="C1", angles='xy',
23+
scale_units='xy', scale=0.5, width=.05)
24+
25+
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
26+
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
27+
ax.set_axisbelow(True)
28+
ax.grid(linewidth=0.7, color="0.75")
29+
30+
plt.show()

plot_types/B_arrays/e_streamline.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
========================
3+
streamplot([X, Y], U, V)
4+
========================
5+
"""
6+
import matplotlib.pyplot as plt
7+
import numpy as np
8+
9+
fig = plt.figure(figsize=(2, 2))
10+
plt.rcParams['axes.linewidth'] = 1.5
11+
plt.rcParams['xtick.major.size'] = 0.0
12+
plt.rcParams['ytick.major.size'] = 0.0
13+
d = 0.01
14+
ax = fig.add_axes([d, d, 1-2*d, 1-2*d])
15+
16+
# make a stream function and contour it:
17+
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
18+
Z = (1 - X/2. + X**5 + Y**3) * np.exp(-X**2 - Y**2)
19+
Z = Z - Z.min()
20+
ax.contour(X, Y, Z, colors='C0', alpha=0.5, zorder=1, linewidths=3)
21+
22+
# make U and V out of the streamfunction
23+
V = np.diff(Z[1:, :], axis=1)
24+
U = -np.diff(Z[:, 1:], axis=0)
25+
# make a streamplot from U and V:
26+
ax.streamplot(X[1:, 1:], Y[1:, 1:], U, V, color='C1', zorder=2)
27+
28+
plt.show()

plot_types/C_stats/README.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. _array_plots:
2+
3+
Specialized statistics plots
4+
============================
5+
6+
Matplotlib has some specialized plots for statistical analysis.

0 commit comments

Comments
 (0)