Skip to content
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

MAINT deprecated 'spectral' in favor of 'nipy_spectral' #7416

Merged
merged 6 commits into from
Nov 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 26 additions & 3 deletions boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,27 @@ def {name}():

"""

CMAP_TEMPLATE_DEPRECATED = AUTOGEN_MSG + """
def {name}():
'''
set the default colormap to {name} and apply to current image if any.
See help(colormaps) for more information
'''
from matplotlib.cbook import warn_deprecated
warn_deprecated(
"2.0",
name="{name}",
obj_type="colormap"
)

rc('image', cmap='{name}')
im = gci()

if im is not None:
im.set_cmap(cm.{name})

"""


def boilerplate_gen():
"""Generator of lines for the automated part of pyplot."""
Expand Down Expand Up @@ -322,16 +343,18 @@ def format_value(value):
'spring',
'summer',
'winter',
'spectral',

'magma',
'inferno',
'plasma',
'viridis'
'viridis',
"nipy_spectral"
)
deprecated_cmaps = ("spectral", )
# add all the colormaps (autumn, hsv, ....)
for name in cmaps:
yield CMAP_TEMPLATE.format(name=name)
for name in deprecated_cmaps:
yield CMAP_TEMPLATE_DEPRECATED.format(name=name)

yield ''
yield '_setup_pyplot_info_docstrings()'
Expand Down
6 changes: 3 additions & 3 deletions doc/users/image_tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ Note that you can also change colormaps on existing plot objects using the
.. sourcecode:: ipython

In [10]: imgplot = plt.imshow(lum_img)
In [11]: imgplot.set_cmap('spectral')
In [11]: imgplot.set_cmap('nipy_spectral')

.. plot::

Expand All @@ -213,7 +213,7 @@ Note that you can also change colormaps on existing plot objects using the
img = mpimg.imread('../_static/stinkbug.png')
lum_img = img[:, :, 0]
imgplot = plt.imshow(lum_img)
imgplot.set_cmap('spectral')
imgplot.set_cmap('nipy_spectral')

.. note::

Expand Down Expand Up @@ -249,7 +249,7 @@ do that by adding color bars.
img = mpimg.imread('../_static/stinkbug.png')
lum_img = img[:, :, 0]
imgplot = plt.imshow(lum_img)
imgplot.set_cmap('spectral')
imgplot.set_cmap('nipy_spectral')
plt.colorbar()

This adds a colorbar to your existing figure. This won't
Expand Down
22 changes: 20 additions & 2 deletions lib/matplotlib/_cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

from matplotlib.cbook import warn_deprecated
import numpy as np

_binary_data = {
Expand Down Expand Up @@ -1365,7 +1366,24 @@ def gfunc32(x):
)


datad = {
class _deprecation_datad(dict):
"""
This class only exists for the purpose of raising an appropriate warning
for the deprecation of spectral. It should be remove in 2.2, once the
colormap spectral disappears.
"""
def __getitem__(self, key):
if key in ["spectral", "spectral_r"]:
warn_deprecated(
"2.0",
name="spectral and spectral_r",
alternative="nipy_spectral and nipy_spectral_r",
obj_type="colormap"
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want to make the message dynamic for spectral_r as well ? I can see pros and cons to both.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to be lazy, and not do it, but… maybe I should.

return super(_deprecation_datad, self).__getitem__(key)


datad = _deprecation_datad({
'afmhot': _afmhot_data,
'autumn': _autumn_data,
'bone': _bone_data,
Expand Down Expand Up @@ -1394,7 +1412,7 @@ def gfunc32(x):
'winter': _winter_data,
'nipy_spectral': _nipy_spectral_data,
'spectral': _nipy_spectral_data, # alias for backward compatibility
}
})


datad['Blues'] = _Blues_data
Expand Down
33 changes: 19 additions & 14 deletions lib/matplotlib/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
import six

import os

import warnings as _warnings # To remove once spectral is removed
import numpy as np
from numpy import ma
import matplotlib as mpl
import matplotlib.colors as colors
import matplotlib.cbook as cbook
from matplotlib._cm import datad
from matplotlib._cm import datad, _deprecation_datad
from matplotlib._cm import cubehelix
from matplotlib._cm_listed import cmaps as cmaps_listed

cmap_d = dict()
cmap_d = _deprecation_datad()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that line 88 of this file will likely trigger the deprecation warning if I'm not wrong, as it loop through all the colormap to build the reversed ones. Not sure what we can do about the though. Just pointing it out.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argh… you are right.
I'll fix that.


# reverse all the colormaps.
# reversed colormaps have '_r' appended to the name.
Expand Down Expand Up @@ -81,17 +81,22 @@ def _generate_cmap(name, lutsize):

LUTSIZE = mpl.rcParams['image.lut']

# Generate the reversed specifications ...
for cmapname in list(six.iterkeys(datad)):
spec = datad[cmapname]
spec_reversed = _reverse_cmap_spec(spec)
datad[cmapname + '_r'] = spec_reversed

# Precache the cmaps with ``lutsize = LUTSIZE`` ...

# Use datad.keys() to also add the reversed ones added in the section above:
for cmapname in six.iterkeys(datad):
cmap_d[cmapname] = _generate_cmap(cmapname, LUTSIZE)
# We silence warnings here to avoid raising the deprecation warning for
# spectral/spectral_r when this module is imported.
with _warnings.catch_warnings():
_warnings.simplefilter("ignore")
# Generate the reversed specifications ...
for cmapname in list(six.iterkeys(datad)):
spec = datad[cmapname]
spec_reversed = _reverse_cmap_spec(spec)
datad[cmapname + '_r'] = spec_reversed

# Precache the cmaps with ``lutsize = LUTSIZE`` ...

# Use datad.keys() to also add the reversed ones added in the section
# above:
for cmapname in six.iterkeys(datad):
cmap_d[cmapname] = _generate_cmap(cmapname, LUTSIZE)

cmap_d.update(cmaps_listed)

Expand Down
1 change: 0 additions & 1 deletion lib/matplotlib/pylab.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@
spring - set the default colormap to spring
summer - set the default colormap to summer
winter - set the default colormap to winter
spectral - set the default colormap to spectral

_Event handling

Expand Down
68 changes: 46 additions & 22 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2605,7 +2605,8 @@ def boxplot(x, notch=None, sym=None, vert=None, whis=None, positions=None,
conf_intervals=None, meanline=None, showmeans=None, showcaps=None,
showbox=None, showfliers=None, boxprops=None, labels=None,
flierprops=None, medianprops=None, meanprops=None, capprops=None,
whiskerprops=None, manage_xticks=True, hold=None, data=None):
whiskerprops=None, manage_xticks=True, autorange=False, zorder=None,
hold=None, data=None):
ax = gca()
# allow callers to override the hold state by passing hold=True|False
washold = ax.ishold()
Expand All @@ -2624,7 +2625,8 @@ def boxplot(x, notch=None, sym=None, vert=None, whis=None, positions=None,
flierprops=flierprops, medianprops=medianprops,
meanprops=meanprops, capprops=capprops,
whiskerprops=whiskerprops,
manage_xticks=manage_xticks, data=data)
manage_xticks=manage_xticks, autorange=autorange,
zorder=zorder, data=data)
finally:
ax.hold(washold)

Expand Down Expand Up @@ -2812,17 +2814,17 @@ def fill_between(x, y1, y2=0, where=None, interpolate=False, step=None,
# This function was autogenerated by boilerplate.py. Do not edit as
# changes will be lost
@_autogen_docstring(Axes.fill_betweenx)
def fill_betweenx(y, x1, x2=0, where=None, step=None, hold=None, data=None,
**kwargs):
def fill_betweenx(y, x1, x2=0, where=None, step=None, interpolate=False,
hold=None, data=None, **kwargs):
ax = gca()
# allow callers to override the hold state by passing hold=True|False
washold = ax.ishold()

if hold is not None:
ax.hold(hold)
try:
ret = ax.fill_betweenx(y, x1, x2=x2, where=where, step=step, data=data,
**kwargs)
ret = ax.fill_betweenx(y, x1, x2=x2, where=where, step=step,
interpolate=interpolate, data=data, **kwargs)
finally:
ax.hold(washold)

Expand Down Expand Up @@ -2857,7 +2859,7 @@ def hexbin(x, y, C=None, gridsize=100, bins=None, xscale='linear',
# This function was autogenerated by boilerplate.py. Do not edit as
# changes will be lost
@_autogen_docstring(Axes.hist)
def hist(x, bins=10, range=None, normed=False, weights=None, cumulative=False,
def hist(x, bins=None, range=None, normed=False, weights=None, cumulative=False,
bottom=None, histtype='bar', align='mid', orientation='vertical',
rwidth=None, log=False, color=None, label=None, stacked=False,
hold=None, data=None, **kwargs):
Expand Down Expand Up @@ -3285,7 +3287,8 @@ def step(x, y, *args, **kwargs):
@_autogen_docstring(Axes.streamplot)
def streamplot(x, y, u, v, density=1, linewidth=None, color=None, cmap=None,
norm=None, arrowsize=1, arrowstyle='-|>', minlength=0.1,
transform=None, zorder=2, start_points=None, hold=None, data=None):
transform=None, zorder=None, start_points=None, hold=None,
data=None):
ax = gca()
# allow callers to override the hold state by passing hold=True|False
washold = ax.ishold()
Expand Down Expand Up @@ -3722,20 +3725,6 @@ def winter():
im.set_cmap(cm.winter)


# This function was autogenerated by boilerplate.py. Do not edit as
# changes will be lost
def spectral():
'''
set the default colormap to spectral and apply to current image if any.
See help(colormaps) for more information
'''
rc('image', cmap='spectral')
im = gci()

if im is not None:
im.set_cmap(cm.spectral)


# This function was autogenerated by boilerplate.py. Do not edit as
# changes will be lost
def magma():
Expand Down Expand Up @@ -3791,4 +3780,39 @@ def viridis():
if im is not None:
im.set_cmap(cm.viridis)


# This function was autogenerated by boilerplate.py. Do not edit as
# changes will be lost
def nipy_spectral():
'''
set the default colormap to nipy_spectral and apply to current image if any.
See help(colormaps) for more information
'''
rc('image', cmap='nipy_spectral')
im = gci()

if im is not None:
im.set_cmap(cm.nipy_spectral)


# This function was autogenerated by boilerplate.py. Do not edit as
# changes will be lost
def spectral():
'''
set the default colormap to spectral and apply to current image if any.
See help(colormaps) for more information
'''
from matplotlib.cbook import warn_deprecated
warn_deprecated(
"2.0",
name="spectral",
obj_type="colormap"
)

rc('image', cmap='spectral')
im = gci()

if im is not None:
im.set_cmap(cm.spectral)

_setup_pyplot_info_docstrings()
2 changes: 1 addition & 1 deletion lib/mpl_toolkits/tests/test_axes_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_imagegrid_cbar_mode_edge():
cbar_mode='edge')
ax1, ax2, ax3, ax4, = grid

im1 = ax1.imshow(arr.real, cmap='spectral')
im1 = ax1.imshow(arr.real, cmap='nipy_spectral')
im2 = ax2.imshow(arr.imag, cmap='hot')
im3 = ax3.imshow(np.abs(arr), cmap='jet')
im4 = ax4.imshow(np.arctan2(arr.imag, arr.real), cmap='hsv')
Expand Down