-
-
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 1 commit
7ee65ef
ceff6f3
fbbf5bb
73fb325
d87156f
11590e6
cce4441
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1645,33 +1645,40 @@ def colors(): | |
|
||
def colormaps(): | ||
""" | ||
matplotlib provides a number of colormaps, a complete list of which can | ||
be found in `cm._cmapnames`. | ||
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, | ||
using a keyword argument:: | ||
|
||
imshow(X, cmap=cm.hot) | ||
|
||
Additionally, for the "base" colormaps below, you can set the colormap | ||
post-hoc using the corresponding pylab interface function:: | ||
or post-hoc using the :func:`set_cmap` function:: | ||
|
||
imshow(X) | ||
pyplot.set_cmap('hot') | ||
pyplot.set_cmap('jet') | ||
|
||
In interactive mode, this will update the colormap allowing you to | ||
see which one works best for your data. Additionally, for the "base" | ||
colormaps below, you can set the colormap using the corresponding pylab | ||
shortcut interface function:: | ||
|
||
imshow(X) | ||
hot() | ||
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'm not a fan of the inconsistency of some colormaps being available this way and others not. On the other hand, I don't know if we want to pollute the pyplot namespace further by adding more colormaps there. It might be nice to have something like:
work. What do others think? 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. And that function could be used to set an rcparam for default colormap... 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 had the same thoughts. The post-hoc functions are copied from Matlab (except Maybe something shorter like 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. There is |
||
jet() | ||
|
||
In interactive mode, this will update the colormap allowing you to | ||
see which one works best for your data. | ||
|
||
All colormaps can be reversed by appending ``_r``: For instance, | ||
All built-in colormaps can be reversed by appending ``_r``: For instance, | ||
``gray_r`` is the reverse of ``gray``. | ||
|
||
There are 3 common color schemes used in visualization: | ||
|
||
1. Sequential schemes, for unipolar data that progresses from low to high | ||
2. Diverging schemes, for bipolar data that emphasizes positive or negative | ||
deviations from a central value | ||
3. Qualitative schemes, which don't have a relationship to magnitude | ||
2. Diverging schemes, for bipolar data that emphasizes positive or | ||
negative deviations from a central value | ||
3. Qualitative schemes, for categorical data where color doesn't have a | ||
relationship to magnitude | ||
|
||
The base colormaps are: | ||
|
||
|
@@ -1725,8 +1732,9 @@ def colormaps(): | |
gist_yarg (identical to *gray_r*) | ||
============ ======================================================= | ||
|
||
The following 34 colormaps are based on the `ColorBrewer <http://colorbrewer.org>`_ | ||
color specifications and designs developed by Cynthia Brewer: | ||
The following 34 colormaps are based on the `ColorBrewer | ||
<http://colorbrewer.org>`_ color specifications and designs developed by | ||
Cynthia Brewer: | ||
|
||
Diverging: | ||
|
||
|
@@ -1775,7 +1783,7 @@ def colormaps(): | |
Other miscellaneous schemes: | ||
|
||
========= ======================================================= | ||
Colormap Description | ||
Colormap Description | ||
========= ======================================================= | ||
afmhot sequential black-orange-yellow-white blackbody | ||
spectrum, commonly used in atomic force microscopy | ||
|
@@ -1819,14 +1827,16 @@ def colormaps(): | |
<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. | ||
<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>`_ | ||
.. [#] 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 | ||
|
||
""" | ||
pass | ||
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).