Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 11590e6

Browse files
committed
make colormaps() return a list of all colormaps
1 parent d87156f commit 11590e6

1 file changed

Lines changed: 28 additions & 18 deletions

File tree

lib/matplotlib/pyplot.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,33 +1645,40 @@ def colors():
16451645

16461646
def colormaps():
16471647
"""
1648-
matplotlib provides a number of colormaps, a complete list of which can
1649-
be found in `cm._cmapnames`.
1648+
Matplotlib provides a number of colormaps, and others can be added using
1649+
:func:`register_cmap`. This function documents the built-in colormaps,
1650+
and will also return a list of all registered colormaps if called.
16501651
16511652
You can set the colormap for an image, pcolor, scatter, etc,
16521653
using a keyword argument::
16531654
16541655
imshow(X, cmap=cm.hot)
16551656
1656-
Additionally, for the "base" colormaps below, you can set the colormap
1657-
post-hoc using the corresponding pylab interface function::
1657+
or post-hoc using the :func:`set_cmap` function::
1658+
1659+
imshow(X)
1660+
pyplot.set_cmap('hot')
1661+
pyplot.set_cmap('jet')
1662+
1663+
In interactive mode, this will update the colormap allowing you to
1664+
see which one works best for your data. Additionally, for the "base"
1665+
colormaps below, you can set the colormap using the corresponding pylab
1666+
shortcut interface function::
16581667
16591668
imshow(X)
16601669
hot()
16611670
jet()
16621671
1663-
In interactive mode, this will update the colormap allowing you to
1664-
see which one works best for your data.
1665-
1666-
All colormaps can be reversed by appending ``_r``: For instance,
1672+
All built-in colormaps can be reversed by appending ``_r``: For instance,
16671673
``gray_r`` is the reverse of ``gray``.
16681674
16691675
There are 3 common color schemes used in visualization:
16701676
16711677
1. Sequential schemes, for unipolar data that progresses from low to high
1672-
2. Diverging schemes, for bipolar data that emphasizes positive or negative
1673-
deviations from a central value
1674-
3. Qualitative schemes, which don't have a relationship to magnitude
1678+
2. Diverging schemes, for bipolar data that emphasizes positive or
1679+
negative deviations from a central value
1680+
3. Qualitative schemes, for categorical data where color doesn't have a
1681+
relationship to magnitude
16751682
16761683
The base colormaps are:
16771684
@@ -1725,8 +1732,9 @@ def colormaps():
17251732
gist_yarg (identical to *gray_r*)
17261733
============ =======================================================
17271734
1728-
The following 34 colormaps are based on the `ColorBrewer <http://colorbrewer.org>`_
1729-
color specifications and designs developed by Cynthia Brewer:
1735+
The following 34 colormaps are based on the `ColorBrewer
1736+
<http://colorbrewer.org>`_ color specifications and designs developed by
1737+
Cynthia Brewer:
17301738
17311739
Diverging:
17321740
@@ -1775,7 +1783,7 @@ def colormaps():
17751783
Other miscellaneous schemes:
17761784
17771785
========= =======================================================
1778-
Colormap Description
1786+
Colormap Description
17791787
========= =======================================================
17801788
afmhot sequential black-orange-yellow-white blackbody
17811789
spectrum, commonly used in atomic force microscopy
@@ -1819,14 +1827,16 @@ def colormaps():
18191827
<http://www.ncl.ucar.edu/Document/Graphics/color_table_gallery.shtml>`_
18201828
18211829
.. [#] See `Diverging Color Maps for Scientific Visualization
1822-
<http://www.cs.unm.edu/~kmorel/documents/ColorMaps/>`_ by Kenneth Moreland.
1830+
<http://www.cs.unm.edu/~kmorel/documents/ColorMaps/>`_ by Kenneth
1831+
Moreland.
18231832
1824-
.. [#] See `A Color Map for Effective Black-and-White Rendering of Color-Scale
1825-
Images <http://www.mathworks.com/matlabcentral/fileexchange/2662-cmrmap-m>`_
1833+
.. [#] See `A Color Map for Effective Black-and-White Rendering of
1834+
Color-Scale Images
1835+
<http://www.mathworks.com/matlabcentral/fileexchange/2662-cmrmap-m>`_
18261836
by Carey Rappaport
18271837
18281838
"""
1829-
pass
1839+
return sorted(cm.cmap_d.keys())
18301840

18311841

18321842
## Plotting part 1: manually generated functions and wrappers ##

0 commit comments

Comments
 (0)