-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
DOC: colormaps docstring update #889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7ee65ef
ceff6f3
fbbf5bb
73fb325
d87156f
11590e6
cce4441
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1645,39 +1645,232 @@ def colors(): | |
|
||
def colormaps(): | ||
""" | ||
matplotlib provides the following colormaps. | ||
|
||
* autumn | ||
* bone | ||
* cool | ||
* copper | ||
* flag | ||
* gray | ||
* hot | ||
* hsv | ||
* jet | ||
* pink | ||
* prism | ||
* spring | ||
* summer | ||
* winter | ||
* spectral | ||
Matplotlib provides a number of colormaps, and others can be added using | ||
:func:`register_cmap`. This function documents the built-in colormaps, | ||
and will also return a list of all registered colormaps if called. | ||
|
||
You can set the colormap for an image, pcolor, scatter, etc, | ||
either as a keyword argument:: | ||
using a keyword argument:: | ||
|
||
imshow(X, cmap=cm.hot) | ||
|
||
or post-hoc using the corresponding pylab interface function:: | ||
or using the :func:`set_cmap` function:: | ||
|
||
imshow(X) | ||
pyplot.set_cmap('hot') | ||
pyplot.set_cmap('jet') | ||
|
||
In interactive mode, :func:`set_cmap` will update the colormap post-hoc, | ||
allowing you to see which one works best for your data. | ||
|
||
All built-in colormaps can be reversed by appending ``_r``: For instance, | ||
``gray_r`` is the reverse of ``gray``. | ||
|
||
There are several common color schemes used in visualization: | ||
|
||
Sequential schemes | ||
for unipolar data that progresses from low to high | ||
Diverging schemes | ||
for bipolar data that emphasizes positive or negative deviations from a | ||
central value | ||
Cyclic schemes | ||
meant for plotting values that wrap around at the | ||
endpoints, such as phase angle, wind direction, or time of day | ||
Qualitative schemes | ||
for nominal data that has no inherent ordering, where color is used | ||
only to distinguish categories | ||
|
||
The base colormaps are (with the exception of `spectral`) derived from | ||
those of the same name provided with Matlab: | ||
|
||
========= ======================================================= | ||
Colormap Description | ||
========= ======================================================= | ||
autumn sequential linearly-increasing shades of red-orange-yellow | ||
bone sequential increasing black-white color map with | ||
a tinge of blue, to emulate X-ray film | ||
cool linearly-decreasing shades of cyan-magenta | ||
copper sequential increasing shades of black-copper | ||
flag repetitive red-white-blue-black pattern (not cyclic at | ||
endpoints) | ||
gray sequential linearly-increasing black-to-white | ||
grayscale | ||
hot sequential black-red-yellow-white, to emulate blackbody | ||
radiation from an object at increasing temperatures | ||
hsv cyclic red-yellow-green-cyan-blue-magenta-red, formed | ||
by changing the hue component in the HSV color space | ||
jet a spectral map with dark endpoints, blue-cyan-yellow-red; | ||
based on a fluid-jet simulation by NCSA [#]_ | ||
pink sequential increasing pastel black-pink-white, meant | ||
for sepia tone colorization of photographs | ||
prism repetitive red-yellow-green-blue-purple-...-green pattern | ||
(not cyclic at endpoints) | ||
spring linearly-increasing shades of magenta-yellow | ||
summer sequential linearly-increasing shades of green-yellow | ||
winter linearly-increasing shades of blue-green | ||
spectral black-purple-blue-green-yellow-red-white spectrum | ||
========= ======================================================= | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems it would be more fair to acknowledge here that all but the last are designed to match their Matlab counterparts, or something to that effect (if that is the case). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah they're all copied from matlab except spectral, but I wasn't sure if that should be mentioned or not. any ideas for wording? they are also used in other things like h5utils, but, again, copied from matlab. http://ab-initio.mit.edu/wiki/index.php/Color_tables_in_h5topng There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "With the exception of spectral, the above colormaps are based on those of the same name provided by Matlab." I don't know how they were derived or extracted; alternative wording suggestions are welcome. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added "The base colormaps are (with the exception of |
||
For the above list only, you can also set the colormap using the | ||
corresponding pylab shortcut interface function, similar to Matlab:: | ||
|
||
imshow(X) | ||
hot() | ||
jet() | ||
|
||
In interactive mode, this will update the colormap allowing you to | ||
see which one works best for your data. | ||
""" | ||
pass | ||
The next set of palettes are from the `Yorick scientific visualisation | ||
package <http://yorick.sourceforge.net/index.php>`_, an evolution of | ||
the GIST package, both by David H. Munro: | ||
|
||
============ ======================================================= | ||
Colormap Description | ||
============ ======================================================= | ||
gist_earth mapmaker's colors from dark blue deep ocean to green | ||
lowlands to brown highlands to white mountains | ||
gist_heat sequential increasing black-red-orange-white, to emulate | ||
blackbody radiation from an iron bar as it grows hotter | ||
gist_ncar pseudo-spectral black-blue-green-yellow-red-purple-white | ||
colormap from National Center for Atmospheric | ||
Research [#]_ | ||
gist_rainbow runs through the colors in spectral order from red to | ||
violet at full saturation (like *hsv* but not cyclic) | ||
gist_stern "Stern special" color table from Interactive Data | ||
Language software | ||
============ ======================================================= | ||
|
||
The following colormaps are based on the `ColorBrewer | ||
<http://colorbrewer.org>`_ color specifications and designs developed by | ||
Cynthia Brewer: | ||
|
||
ColorBrewer Diverging (luminance is highest at the midpoint, and | ||
decreases towards differently-colored endpoints): | ||
|
||
======== =================================== | ||
Colormap Description | ||
======== =================================== | ||
BrBG brown, white, blue-green | ||
PiYG pink, white, yellow-green | ||
PRGn purple, white, green | ||
PuOr orange, white, purple | ||
RdBu red, white, blue | ||
RdGy red, white, gray | ||
RdYlBu red, yellow, blue | ||
RdYlGn red, yellow, green | ||
Spectral red, orange, yellow, green, blue | ||
======== =================================== | ||
|
||
ColorBrewer Sequential (luminance decreases monotonically): | ||
|
||
======== ==================================== | ||
Colormap Description | ||
======== ==================================== | ||
Blues white to dark blue | ||
BuGn white, light blue, dark green | ||
BuPu white, light blue, dark purple | ||
GnBu white, light green, dark blue | ||
Greens white to dark green | ||
Greys white to black (not linear) | ||
Oranges white, orange, dark brown | ||
OrRd white, orange, dark red | ||
PuBu white, light purple, dark blue | ||
PuBuGn white, light purple, dark green | ||
PuRd white, light purple, dark red | ||
Purples white to dark purple | ||
RdPu white, pink, dark purple | ||
Reds white to dark red | ||
YlGn light yellow, dark green | ||
YlGnBu light yellow, light green, dark blue | ||
YlOrBr light yellow, orange, dark brown | ||
YlOrRd light yellow, orange, dark red | ||
======== ==================================== | ||
|
||
ColorBrewer Qualitative: | ||
|
||
(For plotting nominal data, :class:`ListedColormap` should be used, | ||
not :class:`LinearSegmentedColormap`. Different sets of colors are | ||
recommended for different numbers of categories. These continuous | ||
versions of the qualitative schemes may be removed or converted in the | ||
future.) | ||
|
||
* Accent | ||
* Dark2 | ||
* Paired | ||
* Pastel1 | ||
* Pastel2 | ||
* Set1 | ||
* Set2 | ||
* Set3 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might want to note here or elsewhere (footnote?) that the qualitative schemes here are illustrative, and that ordinarily they should be generated as discrete maps for the particular number of colors needed, not at quasi-continuous maps. You could even include a reference to the colors.ListedColormap class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is issue #881, for others' reference. Maybe we should "soft deprecate" them by saying they don't really belong here and shouldn't be used? Like gist_gray is identical to gray and should never have existed, so I just list it as "identical to gray". should I go a step further and say "deprecated, use gray instead"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like those suggestions. Maintaining truly bad and/or duplicate colormaps forever is just bad housekeeping, so putting them on a deprecation path makes sense, even if ends up being years before they actually disappear. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I moved the redundant grayscales into their own section and discouraged them, and added a note to the qualitative section. |
||
Other miscellaneous schemes: | ||
|
||
========= ======================================================= | ||
Colormap Description | ||
========= ======================================================= | ||
afmhot sequential black-orange-yellow-white blackbody | ||
spectrum, commonly used in atomic force microscopy | ||
brg blue-red-green | ||
bwr diverging blue-white-red | ||
coolwarm diverging blue-gray-red, meant to avoid issues with 3D | ||
shading, color blindness, and ordering of colors [#]_ | ||
CMRmap "Default colormaps on color images often reproduce to | ||
confusing grayscale images. The proposed colormap | ||
maintains an aesthetically pleasing color image that | ||
automatically reproduces to a monotonic grayscale with | ||
discrete, quantifiable saturation levels." [#]_ | ||
cubehelix Unlike most other color schemes cubehelix was designed | ||
by D.A. Green to be monotonically increasing in terms | ||
of perceived brightness. Also, when printed on a black | ||
and white postscript printer, the scheme results in a | ||
greyscale with monotonically increasing brightness. | ||
This color scheme is named cubehelix because the r,g,b | ||
values produced can be visualised as a squashed helix | ||
around the diagonal in the r,g,b color cube. | ||
gnuplot gnuplot's traditional pm3d scheme | ||
(black-blue-red-yellow) | ||
gnuplot2 sequential color printable as gray | ||
(black-blue-violet-yellow-white) | ||
ocean green-blue-white | ||
rainbow spectral purple-blue-green-yellow-orange-red colormap | ||
with diverging luminance | ||
seismic diverging blue-white-red | ||
terrain mapmaker's colors, blue-green-yellow-brown-white, | ||
originally from IGOR Pro | ||
========= ======================================================= | ||
|
||
The following colormaps are redundant and may be removed in future | ||
versions. It's recommended to use *gray* or *gray_r* instead, which | ||
produce identical output: | ||
|
||
========= ======================================================= | ||
Colormap Description | ||
========= ======================================================= | ||
gist_gray identical to *gray* | ||
gist_yarg identical to *gray_r* | ||
binary identical to *gray_r* | ||
========= ======================================================= | ||
|
||
.. rubric:: Footnotes | ||
|
||
.. [#] Rainbow colormaps, ``jet`` in particular, are considered a poor | ||
choice for scientific visualization by many researchers: `Rainbow Color | ||
Map (Still) Considered Harmful | ||
<http://www.jwave.vt.edu/%7Erkriz/Projects/create_color_table/color_07.pdf>`_ | ||
|
||
.. [#] Resembles "BkBlAqGrYeOrReViWh200" from NCAR Command | ||
Language. See `Color Table Gallery | ||
<http://www.ncl.ucar.edu/Document/Graphics/color_table_gallery.shtml>`_ | ||
|
||
.. [#] See `Diverging Color Maps for Scientific Visualization | ||
<http://www.cs.unm.edu/~kmorel/documents/ColorMaps/>`_ by Kenneth | ||
Moreland. | ||
|
||
.. [#] See `A Color Map for Effective Black-and-White Rendering of | ||
Color-Scale Images | ||
<http://www.mathworks.com/matlabcentral/fileexchange/2662-cmrmap-m>`_ | ||
by Carey Rappaport | ||
|
||
""" | ||
return sorted(cm.cmap_d.keys()) | ||
|
||
|
||
## Plotting part 1: manually generated functions and wrappers ## | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an identifier with a
_
prefix is supposed to be private, by Python convention, we probably shouldn't recommend using it in the docs. I think we should add a public alias for this and then recommend using the that in the docs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this again, I don't see why this very function
colormap
couldn't be used to return a list of colormap names. This function currently only exists for documentation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making
colormaps()
return a list of colormaps seems pretty logical to me.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably get all the colormaps with:
But having a pyplot function which returns a list of cmap names sounds sensible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, it would be nice to use full sphinx cross linking here (even if the thing you are linking to is not documented). e.g.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well,
cm.cmap_d.keys()
andcm.datad.keys()
both include all the reversed names likegray_r
, which is probably not desirable for printing? _cmapnames is created from datad before it gets the reversed names added to it, so I used that. Didn't realize it shouldn't be exposed to the user like that, though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand, if you use
register_cmap()
, the new colormap shows up incmap_d.keys()
, but not indatad.keys()
or_cmapnames
, socmap_d.keys()
seems like the right answer. I guess showing the_r
colormaps too is legitimate, since ones you create withregister_cmap
don't have any_r
version.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like you are turning over some stones and finding some interesting "features". It might be worth putting some comments/attribute docstrings in
matplotlib.cm
at thedatad
,_cmapnames
andcmap_d
variables. Additionally, some of these inconsistencies might be improved by making the default colormaps go through theregister_cmap
function rather than have them modify the data structures directly (but that is a bigger change, and I can't guarantee that it is entirely sensible).