diff --git a/boilerplate.py b/boilerplate.py index 601cf1bb3eca..1e7715160be7 100644 --- a/boilerplate.py +++ b/boilerplate.py @@ -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.""" @@ -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()' diff --git a/doc/users/image_tutorial.rst b/doc/users/image_tutorial.rst index e4a3b07982ba..14cf3dc9cb43 100644 --- a/doc/users/image_tutorial.rst +++ b/doc/users/image_tutorial.rst @@ -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:: @@ -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:: @@ -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 diff --git a/lib/matplotlib/_cm.py b/lib/matplotlib/_cm.py index 57df2009a129..8523e1cb444b 100644 --- a/lib/matplotlib/_cm.py +++ b/lib/matplotlib/_cm.py @@ -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 = { @@ -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" + ) + return super(_deprecation_datad, self).__getitem__(key) + + +datad = _deprecation_datad({ 'afmhot': _afmhot_data, 'autumn': _autumn_data, 'bone': _bone_data, @@ -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 diff --git a/lib/matplotlib/cm.py b/lib/matplotlib/cm.py index 17fb8d931676..719470fbf253 100644 --- a/lib/matplotlib/cm.py +++ b/lib/matplotlib/cm.py @@ -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() # reverse all the colormaps. # reversed colormaps have '_r' appended to the name. @@ -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) diff --git a/lib/matplotlib/pylab.py b/lib/matplotlib/pylab.py index e11a0b08bd10..a3124c212986 100644 --- a/lib/matplotlib/pylab.py +++ b/lib/matplotlib/pylab.py @@ -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 diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index df6defdfb135..02180ee05cc5 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -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() @@ -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) @@ -2812,8 +2814,8 @@ 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() @@ -2821,8 +2823,8 @@ def fill_betweenx(y, x1, x2=0, where=None, step=None, hold=None, data=None, 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) @@ -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): @@ -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() @@ -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(): @@ -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() diff --git a/lib/mpl_toolkits/tests/test_axes_grid.py b/lib/mpl_toolkits/tests/test_axes_grid.py index 80db9e3d1314..480bf69db63d 100644 --- a/lib/mpl_toolkits/tests/test_axes_grid.py +++ b/lib/mpl_toolkits/tests/test_axes_grid.py @@ -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')