Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9ac3003

Browse filesBrowse files
NelleVQuLogic
authored andcommitted
Merge pull request #7900 from naoyak/mep12-pie-polar
DOC MEP12: pie/polar and color examples + style sheets fix
1 parent 8cbd550 commit 9ac3003
Copy full SHA for 9ac3003

File tree

Expand file treeCollapse file tree

9 files changed

+60
-39
lines changed
Filter options
Expand file treeCollapse file tree

9 files changed

+60
-39
lines changed

‎examples/color/color_cycle_default.py

Copy file name to clipboardExpand all lines: examples/color/color_cycle_default.py
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
"""
2+
====================================
3+
Colors in the default property cycle
4+
====================================
5+
26
Display the colors from the default prop_cycle.
37
"""
4-
58
import numpy as np
69
import matplotlib.pyplot as plt
710

11+
812
prop_cycle = plt.rcParams['axes.prop_cycle']
913
colors = prop_cycle.by_key()['color']
1014

‎examples/color/color_cycle_demo.py

Copy file name to clipboardExpand all lines: examples/color/color_cycle_demo.py
+11-5Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
11
"""
2-
Demo of custom property-cycle settings to control colors and such
3-
for multi-line plots.
2+
===================
3+
Styling with cycler
4+
===================
5+
6+
Demo of custom property-cycle settings to control colors and other style
7+
properties for multi-line plots.
48
59
This example demonstrates two different APIs:
610
7-
1. Setting the default rc-parameter specifying the property cycle.
11+
1. Setting the default rc parameter specifying the property cycle.
812
This affects all subsequent axes (but not axes already created).
9-
2. Setting the property cycle for a specific axes. This only
10-
affects a single axes.
13+
2. Setting the property cycle for a single pair of axes.
1114
"""
1215
from cycler import cycler
1316
import numpy as np
1417
import matplotlib.pyplot as plt
1518

19+
1620
x = np.linspace(0, 2 * np.pi)
1721
offsets = np.linspace(0, 2*np.pi, 4, endpoint=False)
1822
# Create array with shifted-sine curve along each column
1923
yy = np.transpose([np.sin(x + phi) for phi in offsets])
2024

25+
# 1. Setting prop cycle on default rc parameter
2126
plt.rc('lines', linewidth=4)
2227
plt.rc('axes', prop_cycle=(cycler('color', ['r', 'g', 'b', 'y']) +
2328
cycler('linestyle', ['-', '--', ':', '-.'])))
2429
fig, (ax0, ax1) = plt.subplots(nrows=2)
2530
ax0.plot(yy)
2631
ax0.set_title('Set default color cycle to rgby')
2732

33+
# 2. Define prop cycle for single set of axes
2834
ax1.set_prop_cycle(cycler('color', ['c', 'm', 'y', 'k']) +
2935
cycler('lw', [1, 2, 3, 4]))
3036
ax1.plot(yy)

‎examples/color/colormaps_reference.py

Copy file name to clipboardExpand all lines: examples/color/colormaps_reference.py
+8-3Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
"""
2+
==================
3+
Colormap reference
4+
==================
5+
26
Reference for colormaps included with Matplotlib.
37
48
This reference example shows all colormaps included with Matplotlib. Note that
@@ -35,9 +39,9 @@
3539
import numpy as np
3640
import matplotlib.pyplot as plt
3741

42+
3843
# Have colormaps separated into categories:
3944
# http://matplotlib.org/examples/color/colormaps_reference.html
40-
4145
cmaps = [('Perceptually Uniform Sequential',
4246
['viridis', 'inferno', 'plasma', 'magma']),
4347
('Sequential', ['Blues', 'BuGn', 'BuPu',
@@ -65,7 +69,7 @@
6569
gradient = np.vstack((gradient, gradient))
6670

6771

68-
def plot_color_gradients(cmap_category, cmap_list):
72+
def plot_color_gradients(cmap_category, cmap_list, nrows):
6973
fig, axes = plt.subplots(nrows=nrows)
7074
fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99)
7175
axes[0].set_title(cmap_category + ' colormaps', fontsize=14)
@@ -81,7 +85,8 @@ def plot_color_gradients(cmap_category, cmap_list):
8185
for ax in axes:
8286
ax.set_axis_off()
8387

88+
8489
for cmap_category, cmap_list in cmaps:
85-
plot_color_gradients(cmap_category, cmap_list)
90+
plot_color_gradients(cmap_category, cmap_list, nrows)
8691

8792
plt.show()

‎examples/color/named_colors.py

Copy file name to clipboardExpand all lines: examples/color/named_colors.py
+10-17Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,37 @@
11
"""
2-
Visualization of named colors.
2+
========================
3+
Visualizing named colors
4+
========================
35
46
Simple plot example with the named colors and its visual representation.
57
"""
8+
from __future__ import division
69

7-
from __future__ import (absolute_import, division, print_function,
8-
unicode_literals)
9-
10-
import six
11-
12-
import numpy as np
1310
import matplotlib.pyplot as plt
1411
from matplotlib import colors as mcolors
1512

1613

1714
colors = dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS)
1815

19-
# Sort by hue, saturation, value and name.
16+
# Sort colors by hue, saturation, value and name.
2017
by_hsv = sorted((tuple(mcolors.rgb_to_hsv(mcolors.to_rgba(color)[:3])), name)
2118
for name, color in colors.items())
22-
23-
# Get the sorted color names.
2419
sorted_names = [name for hsv, name in by_hsv]
2520

2621
n = len(sorted_names)
2722
ncols = 4
28-
nrows = int(np.ceil(1. * n / ncols))
23+
nrows = n // ncols + 1
2924

3025
fig, ax = plt.subplots(figsize=(8, 5))
3126

27+
# Get height and width
3228
X, Y = fig.get_dpi() * fig.get_size_inches()
33-
34-
# row height
3529
h = Y / (nrows + 1)
36-
# col width
3730
w = X / ncols
3831

3932
for i, name in enumerate(sorted_names):
4033
col = i % ncols
41-
row = int(i / ncols)
34+
row = i // ncols
4235
y = Y - (row * h) - h
4336

4437
xi_line = w * (col + 0.05)
@@ -49,8 +42,8 @@
4942
horizontalalignment='left',
5043
verticalalignment='center')
5144

52-
ax.hlines(
53-
y + h * 0.1, xi_line, xf_line, color=colors[name], linewidth=(h * 0.6))
45+
ax.hlines(y + h * 0.1, xi_line, xf_line,
46+
color=colors[name], linewidth=(h * 0.6))
5447

5548
ax.set_xlim(0, X)
5649
ax.set_ylim(0, Y)

‎examples/pie_and_polar_charts/pie_demo_features.py

Copy file name to clipboardExpand all lines: examples/pie_and_polar_charts/pie_demo_features.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
"""
2+
===============
3+
Basic pie chart
4+
===============
5+
26
Demo of a basic pie chart plus a few additional features.
37
48
In addition to the basic pie chart, this demo shows a few optional features:

‎examples/pie_and_polar_charts/polar_bar_demo.py

Copy file name to clipboardExpand all lines: examples/pie_and_polar_charts/polar_bar_demo.py
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
"""
2+
=======================
3+
Pie chart on polar axis
4+
=======================
5+
26
Demo of bar plot on a polar axis.
37
"""
48
import numpy as np
59
import matplotlib.pyplot as plt
610

711

12+
# Compute pie slices
813
N = 20
914
theta = np.linspace(0.0, 2 * np.pi, N, endpoint=False)
1015
radii = 10 * np.random.rand(N)
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
"""
2+
==========================
3+
Scatter plot on polar axis
4+
==========================
5+
26
Demo of scatter plot on a polar axis.
37
48
Size increases radially in this example and color increases with angle
@@ -8,14 +12,14 @@
812
import matplotlib.pyplot as plt
913

1014

15+
# Compute areas and colors
1116
N = 150
1217
r = 2 * np.random.rand(N)
1318
theta = 2 * np.pi * np.random.rand(N)
1419
area = 200 * r**2
1520
colors = theta
1621

1722
ax = plt.subplot(111, projection='polar')
18-
c = ax.scatter(theta, r, c=colors, s=area, cmap=plt.cm.hsv)
19-
c.set_alpha(0.75)
23+
c = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75)
2024

2125
plt.show()

‎examples/style_sheets/plot_bmh.py

Copy file name to clipboardExpand all lines: examples/style_sheets/plot_bmh.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
from numpy.random import beta
1313
import matplotlib.pyplot as plt
1414

15+
1516
plt.style.use('bmh')
1617

1718

1819
def plot_beta_hist(ax, a, b):
1920
ax.hist(beta(a, b, size=10000), histtype="stepfilled",
2021
bins=25, alpha=0.8, normed=True)
21-
return ax
2222

2323

2424
fig, ax = plt.subplots()

‎examples/style_sheets/plot_fivethirtyeight.py

Copy file name to clipboardExpand all lines: examples/style_sheets/plot_fivethirtyeight.py
+10-10Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@
77
tries to replicate the styles from FiveThirtyEight.com.
88
"""
99

10-
1110
from matplotlib import pyplot as plt
1211
import numpy as np
1312

13+
14+
plt.style.use('fivethirtyeight')
15+
1416
x = np.linspace(0, 10)
1517

1618
# Fixing random state for reproducibility
1719
np.random.seed(19680801)
1820

1921
fig, ax = plt.subplots()
2022

21-
with plt.style.context('fivethirtyeight'):
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")
29-
23+
ax.plot(x, np.sin(x) + x + np.random.randn(50))
24+
ax.plot(x, np.sin(x) + 0.5 * x + np.random.randn(50))
25+
ax.plot(x, np.sin(x) + 2 * x + np.random.randn(50))
26+
ax.plot(x, np.sin(x) - 0.5 * x + np.random.randn(50))
27+
ax.plot(x, np.sin(x) - 2 * x + np.random.randn(50))
28+
ax.plot(x, np.sin(x) + np.random.randn(50))
29+
ax.set_title("'fivethirtyeight' style sheet")
3030

3131
plt.show()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.