Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Change spectral to nipy_spectral, update docs, leave aliases #1127

Merged
merged 3 commits into from

5 participants

endolith Benjamin Root Phil Elson Varoquaux Damon McDougall
endolith

For #879, rename spectral to nipy_spectral (to distinguish from Spectral). Leave spectral as an alias, and spectral() as a shortcut, but only in footnotes.

endolith

Check my docstring formatting. I used

:func:`spectral`

and

 `set_cmap('nipy_spectral')`

for instance. not sure if that's right for functions

Benjamin Root
Collaborator

I think you need double backquotes for the set_cmap call example, but that is completely from memory.

lib/matplotlib/_cm.py
@@ -342,7 +343,7 @@ def gfunc32(x):
'green': ((0., 0., 0.),(1.0, 1.0, 1.0)),
'blue': ((0., 1., 1.),(1.0, 0.5, 0.5))}
-_spectral_data = {'red': [(0.0, 0.0, 0.0), (0.05, 0.4667, 0.4667),
+_nipy_spectral_data = {'red': [(0.0, 0.0, 0.0), (0.05, 0.4667, 0.4667),
(0.10, 0.5333, 0.5333), (0.15, 0.0, 0.0),
(0.20, 0.0, 0.0), (0.25, 0.0, 0.0),
(0.30, 0.0, 0.0), (0.35, 0.0, 0.0),
Damon McDougall Collaborator

I know it's only aesthetic, but it wouldn't hurt to have all the data line up nicely.

Oh I was thinking of refactoring the datad assignments into a single dictionary too. These sorts of OCD formatting are welcome? :)

Damon McDougall Collaborator

Personally, if it makes the code more readable then that's preferred. Ideally, @WeatherGod will weigh in with his PEP8 ninja chops :)

Well PEP8 says not to align code for readability, but I think common usage disagrees. http://www.python.org/dev/peps/pep-0008/#pet-peeves

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
endolith

anything else that needs to be done here?

Phil Elson
Collaborator

@NelleV - your feedback on this would be highly valuable if you have a moment?

Varoquaux
Collaborator

LGTM :+1:

Damon McDougall dmcdougall merged commit b79b55d into from
endolith endolith deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 83 additions and 72 deletions.
  1. +38 −34 lib/matplotlib/_cm.py
  2. +45 −38 lib/matplotlib/pyplot.py
72 lib/matplotlib/_cm.py
View
@@ -2,6 +2,7 @@
Nothing here but dictionaries for generating LinearSegmentedColormaps,
and a dictionary of these dictionaries.
+Documentation for each is in pyplot.colormaps()
"""
from __future__ import print_function
@@ -342,39 +343,41 @@ def gfunc32(x):
'green': ((0., 0., 0.),(1.0, 1.0, 1.0)),
'blue': ((0., 1., 1.),(1.0, 0.5, 0.5))}
-_spectral_data = {'red': [(0.0, 0.0, 0.0), (0.05, 0.4667, 0.4667),
- (0.10, 0.5333, 0.5333), (0.15, 0.0, 0.0),
- (0.20, 0.0, 0.0), (0.25, 0.0, 0.0),
- (0.30, 0.0, 0.0), (0.35, 0.0, 0.0),
- (0.40, 0.0, 0.0), (0.45, 0.0, 0.0),
- (0.50, 0.0, 0.0), (0.55, 0.0, 0.0),
- (0.60, 0.0, 0.0), (0.65, 0.7333, 0.7333),
- (0.70, 0.9333, 0.9333), (0.75, 1.0, 1.0),
- (0.80, 1.0, 1.0), (0.85, 1.0, 1.0),
- (0.90, 0.8667, 0.8667), (0.95, 0.80, 0.80),
- (1.0, 0.80, 0.80)],
- 'green': [(0.0, 0.0, 0.0), (0.05, 0.0, 0.0),
- (0.10, 0.0, 0.0), (0.15, 0.0, 0.0),
- (0.20, 0.0, 0.0), (0.25, 0.4667, 0.4667),
- (0.30, 0.6000, 0.6000), (0.35, 0.6667, 0.6667),
- (0.40, 0.6667, 0.6667), (0.45, 0.6000, 0.6000),
- (0.50, 0.7333, 0.7333), (0.55, 0.8667, 0.8667),
- (0.60, 1.0, 1.0), (0.65, 1.0, 1.0),
- (0.70, 0.9333, 0.9333), (0.75, 0.8000, 0.8000),
- (0.80, 0.6000, 0.6000), (0.85, 0.0, 0.0),
- (0.90, 0.0, 0.0), (0.95, 0.0, 0.0),
- (1.0, 0.80, 0.80)],
- 'blue': [(0.0, 0.0, 0.0), (0.05, 0.5333, 0.5333),
- (0.10, 0.6000, 0.6000), (0.15, 0.6667, 0.6667),
- (0.20, 0.8667, 0.8667), (0.25, 0.8667, 0.8667),
- (0.30, 0.8667, 0.8667), (0.35, 0.6667, 0.6667),
- (0.40, 0.5333, 0.5333), (0.45, 0.0, 0.0),
- (0.5, 0.0, 0.0), (0.55, 0.0, 0.0),
- (0.60, 0.0, 0.0), (0.65, 0.0, 0.0),
- (0.70, 0.0, 0.0), (0.75, 0.0, 0.0),
- (0.80, 0.0, 0.0), (0.85, 0.0, 0.0),
- (0.90, 0.0, 0.0), (0.95, 0.0, 0.0),
- (1.0, 0.80, 0.80)]}
+_nipy_spectral_data = {
+ 'red': [(0.0, 0.0, 0.0), (0.05, 0.4667, 0.4667),
+ (0.10, 0.5333, 0.5333), (0.15, 0.0, 0.0),
+ (0.20, 0.0, 0.0), (0.25, 0.0, 0.0),
+ (0.30, 0.0, 0.0), (0.35, 0.0, 0.0),
+ (0.40, 0.0, 0.0), (0.45, 0.0, 0.0),
+ (0.50, 0.0, 0.0), (0.55, 0.0, 0.0),
+ (0.60, 0.0, 0.0), (0.65, 0.7333, 0.7333),
+ (0.70, 0.9333, 0.9333), (0.75, 1.0, 1.0),
+ (0.80, 1.0, 1.0), (0.85, 1.0, 1.0),
+ (0.90, 0.8667, 0.8667), (0.95, 0.80, 0.80),
+ (1.0, 0.80, 0.80)],
+ 'green': [(0.0, 0.0, 0.0), (0.05, 0.0, 0.0),
+ (0.10, 0.0, 0.0), (0.15, 0.0, 0.0),
+ (0.20, 0.0, 0.0), (0.25, 0.4667, 0.4667),
+ (0.30, 0.6000, 0.6000), (0.35, 0.6667, 0.6667),
+ (0.40, 0.6667, 0.6667), (0.45, 0.6000, 0.6000),
+ (0.50, 0.7333, 0.7333), (0.55, 0.8667, 0.8667),
+ (0.60, 1.0, 1.0), (0.65, 1.0, 1.0),
+ (0.70, 0.9333, 0.9333), (0.75, 0.8000, 0.8000),
+ (0.80, 0.6000, 0.6000), (0.85, 0.0, 0.0),
+ (0.90, 0.0, 0.0), (0.95, 0.0, 0.0),
+ (1.0, 0.80, 0.80)],
+ 'blue': [(0.0, 0.0, 0.0), (0.05, 0.5333, 0.5333),
+ (0.10, 0.6000, 0.6000), (0.15, 0.6667, 0.6667),
+ (0.20, 0.8667, 0.8667), (0.25, 0.8667, 0.8667),
+ (0.30, 0.8667, 0.8667), (0.35, 0.6667, 0.6667),
+ (0.40, 0.5333, 0.5333), (0.45, 0.0, 0.0),
+ (0.5, 0.0, 0.0), (0.55, 0.0, 0.0),
+ (0.60, 0.0, 0.0), (0.65, 0.0, 0.0),
+ (0.70, 0.0, 0.0), (0.75, 0.0, 0.0),
+ (0.80, 0.0, 0.0), (0.85, 0.0, 0.0),
+ (0.90, 0.0, 0.0), (0.95, 0.0, 0.0),
+ (1.0, 0.80, 0.80)],
+}
# 34 colormaps based on color specifications and designs
@@ -1790,7 +1793,8 @@ def gfunc32(x):
'summer': _summer_data,
'terrain': _terrain_data,
'winter': _winter_data,
- 'spectral': _spectral_data
+ 'nipy_spectral': _nipy_spectral_data,
+ 'spectral': _nipy_spectral_data, # alias for backward compatibility
}
83 lib/matplotlib/pyplot.py
View
@@ -1716,8 +1716,8 @@ def colormaps():
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:
+ The base colormaps are derived from those of the same name provided
+ with Matlab:
========= =======================================================
Colormap Description
@@ -1744,7 +1744,6 @@ def colormaps():
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
========= =======================================================
For the above list only, you can also set the colormap using the
@@ -1839,43 +1838,45 @@ def colormaps():
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
- ========= =======================================================
+ ============= =======================================================
+ 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
+ nipy_spectral black-purple-blue-green-yellow-red-white spectrum,
+ originally from the Neuroimaging in Python project
+ 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:
+ versions. It's recommended to use the names in the descriptions
+ instead, which produce identical output:
========= =======================================================
Colormap Description
@@ -1883,6 +1884,7 @@ def colormaps():
gist_gray identical to *gray*
gist_yarg identical to *gray_r*
binary identical to *gray_r*
+ spectral identical to *nipy_spectral* [#]_
========= =======================================================
.. rubric:: Footnotes
@@ -1904,6 +1906,11 @@ def colormaps():
Color-Scale Images
<http://www.mathworks.com/matlabcentral/fileexchange/2662-cmrmap-m>`_
by Carey Rappaport
+
+ .. [#] Changed to distinguish from ColorBrewer's *Spectral* map.
+ :func:`spectral` still works, but
+ ``set_cmap('nipy_spectral')`` is recommended for clarity.
+
"""
return sorted(cm.cmap_d.keys())
Something went wrong with that request. Please try again.