8000 MEP12ify color examples · matplotlib/matplotlib@ab29f84 · GitHub
[go: up one dir, main page]

Skip to content

Commit ab29f84

Browse files
committed
MEP12ify color examples
1 parent 69a634a commit ab29f84

File tree

6 files changed

+36
-26
lines changed

6 files changed

+36
-26
lines changed

examples/color/color_cycle_default.py

Lines 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

Lines 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

Lines 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

Lines 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.
24 F438 19
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/polar_bar_demo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import numpy as np
99
import matplotlib.pyplot as plt
1010

11+
1112
# Fixing random state for reproducibility
1213
np.random.seed(19680801)
1314

examples/pie_and_polar_charts/polar_scatter_demo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import numpy as np
1212
import matplotlib.pyplot as plt
1313

14+
1415
# Fixing random state for reproducibility
1516
np.random.seed(19680801)
1617

0 commit comments

Comments
 (0)
0