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

Skip to content

Commit d49696a

Browse files
committed
New doc gallery for plot_types
1 parent 7ce970e commit d49696a

31 files changed

+656
-2
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,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# from the Matplotlib cheatsheet as used in our gallery:
2+
3+
4+
axes.facecolor: white
5+
axes.edgecolor: black
6+
axes.linewidth: 1.0
7+
axes.grid: True
8+
axes.axisbelow: True # grid/ticks are below elements (e.g., lines, text)
9+
10+
xtick.color: 555555
11+
xtick.direction: out
12+
13+
ytick.color: 555555
14+
ytick.direction: out
15+
16+
grid.color: b0b0b0
17+
grid.linewidth: 0.7
18+
grid.linestyle: - # solid line
19+
20+
figure.facecolor: white
21+
figure.figsize: 2, 2
22+
# make it so the axes labels don't show up. Obviously
23+
# not good style for any quantitative analysis:
24+
figure.subplot.left: 0.01
25+
figure.subplot.right: 0.99
26+
figure.subplot.bottom: 0.01
27+
figure.subplot.top: 0.99
28+

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

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

plot_types/A_basic/b_scatter.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
==================
3+
scatter(X, Y, ...)
4+
==================
5+
"""
6+
import matplotlib.pyplot as plt
7+
import numpy as np
8+
9+
# make the data
10+
np.random.seed(3)
11+
X = 4 + np.random.normal(0, 1.25, 24)
12+
Y = 4 + np.random.normal(0, 1.25, len(X))
13+
14+
# plot
15+
with plt.style.context('cheatsheet_gallery'):
16+
fig, ax = plt.subplots()
17+
18+
ax.scatter(X, Y, 20, zorder=10,
19+
edgecolor="none", facecolor="C1", linewidth=0.25)
20+
21+
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
22+
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
23+
24+
plt.show()

plot_types/A_basic/c_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+
9+
# make data:
10+
np.random.seed(3)
11+
X = 0.5 + np.arange(8)
12+
Y = np.random.uniform(2, 7, len(X))
13+
14+
# plot
15+
with plt.style.context('cheatsheet_gallery'):
16+
fig, ax = plt.subplots()
17+
18+
ax.bar(X, Y, bottom=0, width=1, edgecolor="white",
19+
facecolor="C1", linewidth=0.7)
20+
21+
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
22+
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
23+
24+
plt.show()

plot_types/A_basic/d_stem.py

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

plot_types/A_basic/e_step.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
=====================
3+
step(x, y, where=...)
4+
=====================
5+
"""
6+
import matplotlib.pyplot as plt
7+
import numpy as np
8+
9+
# make data
10+
np.random.seed(3)
11+
X = 0.5 + np.arange(8)
12+
Y = np.random.uniform(2, 7, len(X))
13+
14+
# plot
15+
with plt.style.context('cheatsheet_gallery'):
16+
fig, ax = plt.subplots()
17+
18+
ax.step(X, Y, color="C1", linewidth=2.5)
19+
20+
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
21+
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8))
22+
plt.show()

plot_types/A_basic/f_pie.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
# make data
11+
X = [1, 2, 3, 4]
12+
colors = np.zeros((len(X), 4))
13+
colors[:] = mpl.colors.to_rgba("C1")
14+
colors[:, 3] = np.linspace(0.25, 0.75, len(X))
15+
16+
# plot
17+
with plt.style.context('cheatsheet_gallery'):
18+
fig, ax = plt.subplots()
19+
20+
ax.pie(X, colors=["white"]*len(X), radius=3, center=(4, 4),
21+
wedgeprops={"linewidth": 1, "edgecolor": "white"}, frame=True)
22+
ax.pie(X, colors=colors, radius=3, center=(4, 4),
23+
wedgeprops={"linewidth": 1, "edgecolor": "white"}, frame=True)
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+
28+
plt.show()

plot_types/A_basic/g_fill_between.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
=================================
3+
fill[_between][x](X, Y1, Y2, ...)
4+
=================================
5+
"""
6+
import matplotlib.pyplot as plt
7+
import numpy as np
8+
9+
# make data
10+
np.random.seed(1)
11+
X = np.linspace(0, 8, 16)
12+
Y1 = 3 + 4*X/8 + np.random.uniform(0.0, 0.5, len(X))
13+
Y2 = 1 + 2*X/8 + np.random.uniform(0.0, 0.5, len(X))
14+
15+
# plot
16+
with plt.style.context('cheatsheet_gallery'):
17+
fig, ax = plt.subplots()
18+
19+
ax.fill_between(X, Y1, Y2, color="C1", alpha=.5, linewidth=0)
20+
ax.plot(X, (Y1+Y2)/2, color="C1", linewidth=2.5)
21+
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+
25+
plt.show()

plot_types/B_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/B_arrays/a_imshow.py

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

plot_types/B_arrays/b_pcolormesh.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
# make data:
14+
np.random.seed(3)
15+
Z = np.random.uniform(0.1, 1.0, (8, 8))
16+
x = np.array([0, 0.5, 1.5, 3, 5.2, 6.3, 7.2, 7.5, 8])
17+
y = 1.2**np.arange(0, 9)
18+
19+
# plot
20+
with plt.style.context('cheatsheet_gallery'):
21+
fig, ax = plt.subplots()
22+
23+
# plot:
24+
ax.pcolormesh(x, y, Z, cmap=plt.get_cmap('Oranges'), vmin=0, vmax=1.1)
25+
26+
ax.set_ylim(1, np.max(y))
27+
ax.set_xlim(np.min(x), np.max(x))
28+
plt.show()

plot_types/B_arrays/c_contourf.py

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

plot_types/B_arrays/d_quiver.py

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

plot_types/B_arrays/e_streamplot.py

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

plot_types/C_stats/README.rst

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

plot_types/C_stats/a_hist.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
========================
3+
hist(X, [bins],...)
4+
========================
5+
"""
6+
import matplotlib.pyplot as plt
7+
import numpy as np
8+
9+
# make data
10+
np.random.seed(1)
11+
X = 4 + np.random.normal(0, 1.5, 200)
12+
13+
# plot:
14+
with plt.style.context('cheatsheet_gallery'):
15+
fig, ax = plt.subplots()
16+
17+
ax.hist(X, bins=8, facecolor="C1", linewidth=0.5, edgecolor="white",)
18+
19+
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8))
20+
ax.set_ylim(0, 80), ax.set_yticks(np.arange(1, 80, 10))
21+
22+
plt.show()

0 commit comments

Comments
 (0)