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

Skip to content

Commit 69eee92

Browse files
committed
Convert style sheet examples to MEP12
1 parent 4c5fca7 commit 69eee92

File tree

5 files changed

+54
-22
lines changed

5 files changed

+54
-22
lines changed

examples/style_sheets/plot_bmh.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
"""
2-
This example demonstrates the "bmh" style, which is the design used in the
3-
Bayesian Methods for Hackers online book.
2+
========================================
3+
Bayesian Methods for Hackers style sheet
4+
========================================
5+
6+
This example demonstrates the style used in the Bayesian Methods for Hackers
7+
[1]_ online book.
8+
9+
.. [1] http://camdavidsonpilon.github.io/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/
10+
411
"""
512
from numpy.random import beta
613
import matplotlib.pyplot as plt
714

815
plt.style.use('bmh')
916

1017

11-
def plot_beta_hist(a, b):
12-
plt.hist(beta(a, b, size=10000), histtype="stepfilled",
13-
bins=25, alpha=0.8, normed=True)
14-
return
18+
def plot_beta_hist(ax, a, b):
19+
ax.hist(beta(a, b, size=10000), histtype="stepfilled",
20+
bins=25, alpha=0.8, normed=True)
21+
return ax
22+
1523

16-
plot_beta_hist(10, 10)
17-
plot_beta_hist(4, 12)
18-
plot_beta_hist(50, 12)
19-
plot_beta_hist(6, 55)
24+
fig, ax = plt.subplots()
25+
plot_beta_hist(ax, 10, 10)
26+
plot_beta_hist(ax, 4, 12)
27+
plot_beta_hist(ax, 50, 12)
28+
plot_beta_hist(ax, 6, 55)
29+
ax.set_title("'bmh' style sheet")
2030

2131
plt.show()
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
"""
2+
===========================
3+
Dark background style sheet
4+
===========================
5+
26
This example demonstrates the "dark_background" style, which uses white for
3-
elements that are typically black (text, borders, etc). Note, however, that not
4-
all plot elements default to colors defined by an rc parameter.
7+
elements that are typically black (text, borders, etc). Note that not all plot
8+
elements default to colors defined by an rc parameter.
59
610
"""
711
import numpy as np
@@ -10,14 +14,16 @@
1014

1115
plt.style.use('dark_background')
1216

17+
fig, ax = plt.subplots()
18+
1319
L = 6
1420
x = np.linspace(0, L)
1521
ncolors = len(plt.rcParams['axes.prop_cycle'])
1622
shift = np.linspace(0, L, ncolors, endpoint=False)
1723
for s in shift:
18-
plt.plot(x, np.sin(x + s), 'o-')
19-
plt.xlabel('x-axis')
20-
plt.ylabel('y-axis')
21-
plt.title('title')
24+
ax.plot(x, np.sin(x + s), 'o-')
25+
ax.set_xlabel('x-axis')
26+
ax.set_ylabel('y-axis')
27+
ax.set_title("'dark_background' style sheet")
2228

2329
plt.show()
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
"""
2+
===========================
3+
FiveThirtyEight style sheet
4+
===========================
5+
26
This shows an example of the "fivethirtyeight" styling, which
37
tries to replicate the styles from FiveThirtyEight.com.
48
"""
@@ -12,13 +16,16 @@
1216
# Fixing random state for reproducibility
1317
np.random.seed(19680801)
1418

19+
fig, ax = plt.subplots()
20+
1521
with plt.style.context('fivethirtyeight'):
16-
plt.plot(x, np.sin(x) + x + np.random.randn(50))
17-
plt.plot(x, np.sin(x) + 0.5 * x + np.random.randn(50))
18-
plt.plot(x, np.sin(x) + 2 * x + np.random.randn(50))
19-
plt.plot(x, np.sin(x) - 0.5 * x + np.random.randn(50))
20-
plt.plot(x, np.sin(x) - 2 * x + np.random.randn(50))
21-
plt.plot(x, np.sin(x) + np.random.randn(50))
22+
ax.plot(x, np.sin(x) + x + np.random.randn(50))
23+
ax.plot(x, np.sin(x) + 0.5 * x + np.random.randn(50))
24+
ax.plot(x, np.sin(x) + 2 * x + np.random.randn(50))
25+
ax.plot(x, np.sin(x) - 0.5 * x + np.random.randn(50))
26+
ax.plot(x, np.sin(x) - 2 * x + np.random.randn(50))
27+
ax.plot(x, np.sin(x) + np.random.randn(50))
28+
ax.set_title("'fivethirtyeight' style sheet")
2229

2330

2431
plt.show()

examples/style_sheets/plot_ggplot.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
"""
2+
==================
3+
ggplot style sheet
4+
==================
5+
26
This example demonstrates the "ggplot" style, which adjusts the style to
37
emulate ggplot_ (a popular plotting package for R_).
48

examples/style_sheets/plot_grayscale.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
"""
2+
=====================
3+
Grayscale style sheet
4+
=====================
5+
26
This example demonstrates the "grayscale" style sheet, which changes all colors
37
that are defined as rc parameters to grayscale. Note, however, that not all
48
plot elements default to colors defined by an rc parameter.
@@ -29,6 +33,7 @@ def image_and_patch_example(ax):
2933
plt.style.use('grayscale')
3034

3135
fig, (ax1, ax2) = plt.subplots(ncols=2)
36+
fig.suptitle("'grayscale' style sheet")
3237

3338
color_cycle_example(ax1)
3439
image_and_patch_example(ax2)

0 commit comments

Comments
 (0)