8000 DOC Convert style sheet examples to MEP12 by naoyak · Pull Request #7890 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

DOC Convert style sheet examples to MEP12 #7890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Convert style sheet examples to MEP12
  • Loading branch information
naoyak committed Jan 20, 2017
commit 69eee924c89a54a1e8ac287637d549a8d485ad69
30 changes: 20 additions & 10 deletions examples/style_sheets/plot_bmh.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
"""
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
========================================

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NelleV does the length of the ='s need to match the title?

E.g.,

=====================
 Bayesian Methods for Hackers style sheet
=====================

vs

=========================================
 Bayesian Methods for Hackers style sheet
=========================================

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it does: our documentation build is else going to fail.

(To be precise, lines can be longer, but not shorter than the title)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question to a PEP8 expert (@QuLogic ?) : are URLs longer than 80 characters OK with our pycodestyle setup?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering about that too and pushed this to see if the build would fail.

Obviously there isn't much of a way around this short of using a URL shortener or something.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might ignore URLs in docstrings. You could get it to fit with backslashes, but it'd be ugly.


"""
from numpy.random import beta
import matplotlib.pyplot as plt

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line; the return value is not used for anything.



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()
18 changes: 12 additions & 6 deletions examples/style_sheets/plot_dark_background.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
19 changes: 13 additions & 6 deletions examples/style_sheets/plot_fivethirtyeight.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""
===========================
FiveThirtyEight style sheet
===========================

This shows an example of the "fivethirtyeight" styling, which
tries to replicate the styles from FiveThirtyEight.com.
"""
Expand All @@ -12,13 +16,16 @@
# Fixing random state for reproducibility
np.random.seed(19680801)

fig, ax = plt.subplots()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might need to do this within the context to ensure that general figure styling matches the style.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe change the example to use plt.style.use like the other ones.


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()
4 changes: 4 additions & 0 deletions examples/style_sheets/plot_ggplot.py
Original file line number Diff line number Diff line change
@@ -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_).

Expand Down
5 changes: 5 additions & 0 deletions examples/style_sheets/plot_grayscale.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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)
Expand Down
0