diff --git a/examples/style_sheets/plot_bmh.py b/examples/style_sheets/plot_bmh.py index f44c319a675e..c37f4dbfa534 100644 --- a/examples/style_sheets/plot_bmh.py +++ b/examples/style_sheets/plot_bmh.py @@ -1,6 +1,13 @@ """ -This example demonstrates the "bmh" style, which is the design used in the -Bayesian Methods for Hackers online book. +======================================== +Bayesian Methods for Hackers style sheet +======================================== + +This example demonstrates the style used in the Bayesian Methods for Hackers +[1]_ online book. + +.. [1] http://camdavidsonpilon.github.io/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/ + """ from numpy.random import beta import matplotlib.pyplot as plt @@ -8,14 +15,17 @@ plt.style.use('bmh') -def plot_beta_hist(a, b): - plt.hist(beta(a, b, size=10000), histtype="stepfilled", - bins=25, alpha=0.8, normed=True) - return +def plot_beta_hist(ax, a, b): + ax.hist(beta(a, b, size=10000), histtype="stepfilled", + bins=25, alpha=0.8, normed=True) + return ax + -plot_beta_hist(10, 10) -plot_beta_hist(4, 12) -plot_beta_hist(50, 12) -plot_beta_hist(6, 55) +fig, ax = plt.subplots() +plot_beta_hist(ax, 10, 10) +plot_beta_hist(ax, 4, 12) +plot_beta_hist(ax, 50, 12) +plot_beta_hist(ax, 6, 55) +ax.set_title("'bmh' style sheet") plt.show() diff --git a/examples/style_sheets/plot_dark_background.py b/examples/style_sheets/plot_dark_background.py index dd1f0251b324..4342667cfbe4 100644 --- a/examples/style_sheets/plot_dark_background.py +++ b/examples/style_sheets/plot_dark_background.py @@ -1,7 +1,11 @@ """ +=========================== +Dark background style sheet +=========================== + This example demonstrates the "dark_background" style, which uses white for -elements that are typically black (text, borders, etc). Note, however, that not -all plot elements default to colors defined by an rc parameter. +elements that are typically black (text, borders, etc). Note that not all plot +elements default to colors defined by an rc parameter. """ import numpy as np @@ -10,14 +14,16 @@ plt.style.use('dark_background') +fig, ax = plt.subplots() + L = 6 x = np.linspace(0, L) ncolors = len(plt.rcParams['axes.prop_cycle']) shift = np.linspace(0, L, ncolors, endpoint=False) for s in shift: - plt.plot(x, np.sin(x + s), 'o-') -plt.xlabel('x-axis') -plt.ylabel('y-axis') -plt.title('title') + ax.plot(x, np.sin(x + s), 'o-') +ax.set_xlabel('x-axis') +ax.set_ylabel('y-axis') +ax.set_title("'dark_background' style sheet") plt.show() diff --git a/examples/style_sheets/plot_fivethirtyeight.py b/examples/style_sheets/plot_fivethirtyeight.py index 0f7d560433db..79fb5cd84876 100644 --- a/examples/style_sheets/plot_fivethirtyeight.py +++ b/examples/style_sheets/plot_fivethirtyeight.py @@ -1,4 +1,8 @@ """ +=========================== +FiveThirtyEight style sheet +=========================== + This shows an example of the "fivethirtyeight" styling, which tries to replicate the styles from FiveThirtyEight.com. """ @@ -12,13 +16,16 @@ # Fixing random state for reproducibility np.random.seed(19680801) +fig, ax = plt.subplots() + with plt.style.context('fivethirtyeight'): - plt.plot(x, np.sin(x) + x + np.random.randn(50)) - plt.plot(x, np.sin(x) + 0.5 * x + np.random.randn(50)) - plt.plot(x, np.sin(x) + 2 * x + np.random.randn(50)) - plt.plot(x, np.sin(x) - 0.5 * x + np.random.randn(50)) - plt.plot(x, np.sin(x) - 2 * x + np.random.randn(50)) - plt.plot(x, np.sin(x) + np.random.randn(50)) + ax.plot(x, np.sin(x) + x + np.random.randn(50)) + ax.plot(x, np.sin(x) + 0.5 * x + np.random.randn(50)) + ax.plot(x, np.sin(x) + 2 * x + np.random.randn(50)) + ax.plot(x, np.sin(x) - 0.5 * x + np.random.randn(50)) + ax.plot(x, np.sin(x) - 2 * x + np.random.randn(50)) + ax.plot(x, np.sin(x) + np.random.randn(50)) + ax.set_title("'fivethirtyeight' style sheet") plt.show() diff --git a/examples/style_sheets/plot_ggplot.py b/examples/style_sheets/plot_ggplot.py index e96b28d59b96..c1171f2e3230 100644 --- a/examples/style_sheets/plot_ggplot.py +++ b/examples/style_sheets/plot_ggplot.py @@ -1,4 +1,8 @@ """ +================== +ggplot style sheet +================== + This example demonstrates the "ggplot" style, which adjusts the style to emulate ggplot_ (a popular plotting package for R_). diff --git a/examples/style_sheets/plot_grayscale.py b/examples/style_sheets/plot_grayscale.py index 91a2f97c904e..bbcab02e0228 100644 --- a/examples/style_sheets/plot_grayscale.py +++ b/examples/style_sheets/plot_grayscale.py @@ -1,4 +1,8 @@ """ +===================== +Grayscale style sheet +===================== + This example demonstrates the "grayscale" style sheet, which changes all colors that are defined as rc parameters to grayscale. Note, however, that not all plot elements default to colors defined by an rc parameter. @@ -29,6 +33,7 @@ def image_and_patch_example(ax): plt.style.use('grayscale') fig, (ax1, ax2) = plt.subplots(ncols=2) +fig.suptitle("'grayscale' style sheet") color_cycle_example(ax1) image_and_patch_example(ax2)