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

Skip to content

Commit 64fdd33

Browse files
committed
Merge pull request #7890 from naoyak/mep12-style-sheets
DOC: Convert style sheet examples to MEP12
1 parent ee67d35 commit 64fdd33

File tree

5 files changed

+57
-22
lines changed

5 files changed

+57
-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: 16 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
"""
@@ -9,13 +13,19 @@
913

1014
x = np.linspace(0, 10)
1115

16+
# Fixing random state for reproducibility
17+
np.random.seed(19680801)
18+
19+
fig, ax = plt.subplots()
20+
1221
with plt.style.context('fivethirtyeight'):
13-
plt.plot(x, np.sin(x) + x + np.random.randn(50))
14-
plt.plot(x, np.sin(x) + 0.5 * x + np.random.randn(50))
15-
plt.plot(x, np.sin(x) + 2 * x + np.random.randn(50))
16-
plt.plot(x, np.sin(x) - 0.5 * x + np.random.randn(50))
17-
plt.plot(x, np.sin(x) - 2 * x + np.random.randn(50))
18-
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")
1929

2030

2131
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.
@@ -26,6 +30,7 @@ def image_and_patch_example(ax):
2630
plt.style.use('grayscale')
2731

2832
fig, (ax1, ax2) = plt.subplots(ncols=2)
33+
fig.suptitle("'grayscale' style sheet")
2934

3035
color_cycle_example(ax1)
3136
image_and_patch_example(ax2)

0 commit comments

Comments
 (0)