Skip to content

Commit d4848bb

Browse files
committed
adds two new cyclic color schemes
Matlotlib currently lacks a good, perceptually uniform color scheme for circular data. This adds "sunlight" and "twilight", two viscm-derived color schemes for angular data.
1 parent 1652ed1 commit d4848bb

File tree

4 files changed

+619
-72
lines changed

4 files changed

+619
-72
lines changed

examples/color/colormap_reference.py

Lines changed: 0 additions & 67 deletions
This file was deleted.

examples/color/colormaps_reference.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
"""
2+
Reference for colormaps included with Matplotlib.
3+
4+
This reference example shows all colormaps included with Matplotlib. Note that
5+
any colormap listed here can be reversed by appending "_r" (e.g., "pink_r").
6+
These colormaps are divided into the following categories:
7+
8+
Sequential:
9+
These colormaps are approximately monochromatic colormaps varying smoothly
10+
between two color tones---usually from low saturation (e.g. white) to high
11+
saturation (e.g. a bright blue). Sequential colormaps are ideal for
12+
representing most scientific data since they show a clear progression from
13+
low-to-high values.
14+
15+
Diverging:
16+
These colormaps have a median value (usually light in color) and vary
17+
smoothly to two different color tones at high and low values. Diverging
18+
colormaps are ideal when your data has a median value that is significant
19+
(e.g. 0, such that positive and negative values are represented by
20+
different colors of the colormap).
21+
22+
Qualitative:
23+
These colormaps vary rapidly in color. Qualitative colormaps are useful for
24+
choosing a set of discrete colors. For example::
25+
26+
color_list = plt.cm.Set3(np.linspace(0, 1, 12))
27+
28+
gives a list of RGB colors that are good for plotting a series of lines on
29+
a dark background.
30+
31+
Miscellaneous:
32+
Colormaps that don't fit into the categories above.
33+
34+
"""
35+
import numpy as np
36+
import matplotlib.pyplot as plt
37+
38+
# Have colormaps separated into categories:
39+
# http://matplotlib.org/examples/color/colormaps_reference.html
40+
41+
cmaps = [('Perceptually Uniform Sequential',
42+
['viridis', 'inferno', 'plasma', 'magma']),
43+
('Sequential', ['Blues', 'BuGn', 'BuPu',
44+
'GnBu', 'Greens', 'Greys', 'Oranges', 'OrRd',
45+
'PuBu', 'PuBuGn', 'PuRd', 'Purples', 'RdPu',
46+
'Reds', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd']),
47+
('Sequential (2)', ['afmhot', 'autumn', 'bone', 'cool',
48+
'copper', 'gist_heat', 'gray', 'hot',
49+
'pink', 'spring', 'summer', 'winter']),
50+
('Diverging', ['BrBG', 'bwr', 'coolwarm', 'PiYG', 'PRGn', 'PuOr',
51+
'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn', 'Spectral',
52+
'seismic']),
53+
('Qualitative', ['Accent', 'Dark2', 'Paired', 'Pastel1',
54+
'Pastel2', 'Set1', 'Set2', 'Set3', 'Vega10',
55+
'Vega20', 'Vega20b', 'Vega20c']),
56+
('Miscellaneous', ['gist_earth', 'terrain', 'ocean', 'gist_stern',
57+
'brg', 'CMRmap', 'cubehelix',
58+
'gnuplot', 'gnuplot2', 'gist_ncar',
59+
'nipy_spectral', 'jet', 'rainbow',
60+
'gist_rainbow', 'hsv', 'flag', 'prism']),
61+
('Perceptually Uniform Cyclic', ['twilight', 'sunlight'])]
62+
63+
64+
nrows = max(len(cmap_list) for cmap_category, cmap_list in cmaps)
65+
gradient = np.linspace(0, 1, 256)
66+
gradient = np.vstack((gradient, gradient))
67+
68+
69+
def plot_color_gradients(cmap_category, cmap_list):
70+
fig, axes = plt.subplots(nrows=nrows)
71+
fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99)
72+
axes[0].set_title(cmap_category + ' colormaps', fontsize=14)
73+
74+
for ax, name in zip(axes, cmap_list):
75+
ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name))
76+
pos = list(ax.get_position().bounds)
77+
x_text = pos[0] - 0.01
78+
y_text = pos[1] + pos[3]/2.
79+
fig.text(x_text, y_text, name, va='center', ha='right', fontsize=10)
80+
81+
# Turn off *all* ticks & spines, not just the ones with colormaps.
82+
for ax in axes:
83+
ax.set_axis_off()
84+
85+
for cmap_category, cmap_list in cmaps:
86+
plot_color_gradients(cmap_category, cmap_list)
87+
88+
plt.show()

0 commit comments

Comments
 (0)