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

Skip to content

Commit ce3e40e

Browse files
committed
New doc gallery for plot_types
1 parent bd7df78 commit ce3e40e

31 files changed

+665
-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', '../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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# from http://www.huyng.com/posts/sane-color-scheme-for-matplotlib/
2+
3+
patch.linewidth: 0.5
4+
patch.facecolor: 348ABD # blue
5+
patch.edgecolor: EEEEEE
6+
patch.antialiased: True
7+
8+
font.size: 0.0
9+
10+
axes.facecolor: white
11+
axes.edgecolor: black
12+
axes.linewidth: 1.0
13+
axes.grid: True
14+
axes.titlesize: 0
15+
axes.labelsize: 0
16+
axes.labelcolor: 555555
17+
axes.axisbelow: True # grid/ticks are below elements (e.g., lines, text)
18+
19+
20+
xtick.color: 555555
21+
xtick.direction: out
22+
23+
ytick.color: 555555
24+
ytick.direction: out
25+
26+
grid.color: b0b0b0
27+
grid.linewidth: 0.7
28+
grid.linestyle: - # solid line
29+
30+
figure.facecolor: white
31+
figure.figsize: 2, 2
32+
figure.subplot.left: 0.01
33+
figure.subplot.right: 0.99
34+
figure.subplot.bottom: 0.01
35+
figure.subplot.top: 0.99
36+
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.
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()
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()
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()
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()
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()
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()
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()
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.
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()
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.pcolormesh` is more flexible than `.axes.imshow` in that the
7+
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()
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()
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()
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()
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.

0 commit comments

Comments
 (0)