Skip to content

Commit 17e3090

Browse files
committed
Combine colormap reference examples
1 parent a97d058 commit 17e3090

9 files changed

+83
-192
lines changed

doc/users/image_tutorial.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,9 @@ object:
229229
imgplot = plt.imshow(lum_img)
230230
imgplot.set_cmap('spectral')
231231

232-
There are many other colormap schemes available. See the `list of
233-
colormaps
234-
<http://matplotlib.org/api/pyplot_summary.html#matplotlib.pyplot.colormaps>`_
235-
and `images of the colormaps
236-
<http://matplotlib.org/examples/pylab_examples/show_colormaps.html>`_.
232+
There are many other colormap schemes available. See the `list and
233+
images of the colormaps
234+
<http://matplotlib.org/examples/color/colormaps_reference.html>`_.
237235

238236
.. _`Color Bars`:
239237

doc/users/whats_new.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ Other improvements
542542

543543
* Pim Schellart added a new colormap called "cubehelix".
544544
Sameer Grover also added a colormap called "coolwarm". See it and all
545-
other colormaps :ref:`here <pylab_examples-show_colormaps>`.
545+
other colormaps :ref:`here <color-colormaps_reference>`.
546546

547547
* Many bug fixes and documentation improvements.
548548

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
39+
cmaps = [('Sequential', ['binary', 'Blues', 'BuGn', 'BuPu', 'gist_yarg',
40+
'GnBu', 'Greens', 'Greys', 'Oranges', 'OrRd',
41+
'PuBu', 'PuBuGn', 'PuRd', 'Purples', 'RdPu',
42+
'Reds', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd']),
43+
('Sequential (2)', ['afmhot', 'autumn', 'bone', 'cool', 'copper',
44+
'gist_gray', 'gist_heat', 'gray', 'hot', 'pink',
45+
'spring', 'summer', 'winter']),
46+
('Diverging', ['BrBG', 'bwr', 'coolwarm', 'PiYG', 'PRGn', 'PuOr',
47+
'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn', 'seismic']),
48+
('Qualitative', ['Accent', 'Dark2', 'hsv', 'Paired', 'Pastel1',
49+
'Pastel2', 'Set1', 'Set2', 'Set3', 'spectral']),
50+
('Miscellaneous', ['gist_earth', 'gist_ncar', 'gist_rainbow',
51+
'gist_stern', 'jet', 'brg', 'CMRmap', 'cubehelix',
52+
'gnuplot', 'gnuplot2', 'ocean', 'rainbow',
53+
'terrain', 'flag', 'prism'])]
54+
55+
56+
nrows = max(len(cmap_list) for cmap_category, cmap_list in cmaps)
57+
gradient = np.linspace(0, 1, 256)
58+
gradient = np.vstack((gradient, gradient))
59+
60+
def plot_color_gradients(cmap_category, cmap_list):
61+
fig, axes = plt.subplots(nrows=nrows)
62+
fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99)
63+
axes[0].set_title(cmap_category + ' colormaps', fontsize=14)
64+
65+
for ax, name in zip(axes, cmap_list):
66+
ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name))
67+
pos = list(ax.get_position().bounds)
68+
x_text = pos[0] - 0.01
69+
y_text = pos[1] + pos[3]/2.
70+
fig.text(x_text, y_text, name, va='center', ha='right', fontsize=10)
71+
72+
# Turn off *all* ticks & spines, not just the ones with colormaps.
73+
for ax in axes:
74+
ax.set_axis_off()
75+
76+
for cmap_category, cmap_list in cmaps:
77+
plot_color_gradients(cmap_category, cmap_list)
78+
79+
plt.show()

examples/color/colormaps_reference_diverging.py

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

examples/color/colormaps_reference_miscellaneous.py

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

examples/color/colormaps_reference_qualitative.py

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

examples/color/colormaps_reference_sequential.py

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

examples/color/colormaps_reference_sequential2.py

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

examples/pylab_examples/show_colormaps.py

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

0 commit comments

Comments
 (0)