Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 660aa65

Browse filesBrowse files
authored
Merge pull request #7416 from NelleV/7315_spectral
[MRG+1] MAINT deprecated 'spectral' in favor of 'nipy_spectral'
2 parents d3d10d1 + 954bf7a commit 660aa65
Copy full SHA for 660aa65

File tree

Expand file treeCollapse file tree

7 files changed

+115
-46
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+115
-46
lines changed

‎boilerplate.py

Copy file name to clipboardExpand all lines: boilerplate.py
+26-3Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,27 @@ def {name}():
8787
8888
"""
8989

90+
CMAP_TEMPLATE_DEPRECATED = AUTOGEN_MSG + """
91+
def {name}():
92+
'''
93+
set the default colormap to {name} and apply to current image if any.
94+
See help(colormaps) for more information
95+
'''
96+
from matplotlib.cbook import warn_deprecated
97+
warn_deprecated(
98+
"2.0",
99+
name="{name}",
100+
obj_type="colormap"
101+
)
102+
103+
rc('image', cmap='{name}')
104+
im = gci()
105+
106+
if im is not None:
107+
im.set_cmap(cm.{name})
108+
109+
"""
110+
90111

91112
def boilerplate_gen():
92113
"""Generator of lines for the automated part of pyplot."""
@@ -322,16 +343,18 @@ def format_value(value):
322343
'spring',
323344
'summer',
324345
'winter',
325-
'spectral',
326-
327346
'magma',
328347
'inferno',
329348
'plasma',
330-
'viridis'
349+
'viridis',
350+
"nipy_spectral"
331351
)
352+
deprecated_cmaps = ("spectral", )
332353
# add all the colormaps (autumn, hsv, ....)
333354
for name in cmaps:
334355
yield CMAP_TEMPLATE.format(name=name)
356+
for name in deprecated_cmaps:
357+
yield CMAP_TEMPLATE_DEPRECATED.format(name=name)
335358

336359
yield ''
337360
yield '_setup_pyplot_info_docstrings()'

‎doc/users/image_tutorial.rst

Copy file name to clipboardExpand all lines: doc/users/image_tutorial.rst
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ Note that you can also change colormaps on existing plot objects using the
203203
.. sourcecode:: ipython
204204

205205
In [10]: imgplot = plt.imshow(lum_img)
206-
In [11]: imgplot.set_cmap('spectral')
206+
In [11]: imgplot.set_cmap('nipy_spectral')
207207

208208
.. plot::
209209

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

218218
.. note::
219219

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

255255
This adds a colorbar to your existing figure. This won't

‎lib/matplotlib/_cm.py

Copy file name to clipboardExpand all lines: lib/matplotlib/_cm.py
+20-2Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from __future__ import (absolute_import, division, print_function,
1010
unicode_literals)
1111

12+
from matplotlib.cbook import warn_deprecated
1213
import numpy as np
1314

1415
_binary_data = {
@@ -1365,7 +1366,24 @@ def gfunc32(x):
13651366
)
13661367

13671368

1368-
datad = {
1369+
class _deprecation_datad(dict):
1370+
"""
1371+
This class only exists for the purpose of raising an appropriate warning
1372+
for the deprecation of spectral. It should be remove in 2.2, once the
1373+
colormap spectral disappears.
1374+
"""
1375+
def __getitem__(self, key):
1376+
if key in ["spectral", "spectral_r"]:
1377+
warn_deprecated(
1378+
"2.0",
1379+
name="spectral and spectral_r",
1380+
alternative="nipy_spectral and nipy_spectral_r",
1381+
obj_type="colormap"
1382+
)
1383+
return super(_deprecation_datad, self).__getitem__(key)
1384+
1385+
1386+
datad = _deprecation_datad({
13691387
'afmhot': _afmhot_data,
13701388
'autumn': _autumn_data,
13711389
'bone': _bone_data,
@@ -1394,7 +1412,7 @@ def gfunc32(x):
13941412
'winter': _winter_data,
13951413
'nipy_spectral': _nipy_spectral_data,
13961414
'spectral': _nipy_spectral_data, # alias for backward compatibility
1397-
}
1415+
})
13981416

13991417

14001418
datad['Blues'] = _Blues_data

‎lib/matplotlib/cm.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cm.py
+19-14Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
import six
1111

1212
import os
13-
13+
import warnings as _warnings # To remove once spectral is removed
1414
import numpy as np
1515
from numpy import ma
1616
import matplotlib as mpl
1717
import matplotlib.colors as colors
1818
import matplotlib.cbook as cbook
19-
from matplotlib._cm import datad
19+
from matplotlib._cm import datad, _deprecation_datad
2020
from matplotlib._cm import cubehelix
2121
from matplotlib._cm_listed import cmaps as cmaps_listed
2222

23-
cmap_d = dict()
23+
cmap_d = _deprecation_datad()
2424

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

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

84-
# Generate the reversed specifications ...
85-
for cmapname in list(six.iterkeys(datad)):
86-
spec = datad[cmapname]
87-
spec_reversed = _reverse_cmap_spec(spec)
88-
datad[cmapname + '_r'] = spec_reversed
89-
90-
# Precache the cmaps with ``lutsize = LUTSIZE`` ...
91-
92-
# Use datad.keys() to also add the reversed ones added in the section above:
93-
for cmapname in six.iterkeys(datad):
94-
cmap_d[cmapname] = _generate_cmap(cmapname, LUTSIZE)
84+
# We silence warnings here to avoid raising the deprecation warning for
85+
# spectral/spectral_r when this module is imported.
86+
with _warnings.catch_warnings():
87+
_warnings.simplefilter("ignore")
88+
# Generate the reversed specifications ...
89+
for cmapname in list(six.iterkeys(datad)):
90+
spec = datad[cmapname]
91+
spec_reversed = _reverse_cmap_spec(spec)
92+
datad[cmapname + '_r'] = spec_reversed
93+
94+
# Precache the cmaps with ``lutsize = LUTSIZE`` ...
95+
96+
# Use datad.keys() to also add the reversed ones added in the section
97+
# above:
98+
for cmapname in six.iterkeys(datad):
99+
cmap_d[cmapname] = _generate_cmap(cmapname, LUTSIZE)
95100

96101
cmap_d.update(cmaps_listed)
97102

‎lib/matplotlib/pylab.py

Copy file name to clipboardExpand all lines: lib/matplotlib/pylab.py
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@
121121
spring - set the default colormap to spring
122122
summer - set the default colormap to summer
123123
winter - set the default colormap to winter
124-
spectral - set the default colormap to spectral
125124
126125
_Event handling
127126

‎lib/matplotlib/pyplot.py

Copy file name to clipboardExpand all lines: lib/matplotlib/pyplot.py
+46-22Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,7 +2605,8 @@ def boxplot(x, notch=None, sym=None, vert=None, whis=None, positions=None,
26052605
conf_intervals=None, meanline=None, showmeans=None, showcaps=None,
26062606
showbox=None, showfliers=None, boxprops=None, labels=None,
26072607
flierprops=None, medianprops=None, meanprops=None, capprops=None,
2608-
whiskerprops=None, manage_xticks=True, hold=None, data=None):
2608+
whiskerprops=None, manage_xticks=True, autorange=False, zorder=None,
2609+
hold=None, data=None):
26092610
ax = gca()
26102611
# allow callers to override the hold state by passing hold=True|False
26112612
washold = ax.ishold()
@@ -2624,7 +2625,8 @@ def boxplot(x, notch=None, sym=None, vert=None, whis=None, positions=None,
26242625
flierprops=flierprops, medianprops=medianprops,
26252626
meanprops=meanprops, capprops=capprops,
26262627
whiskerprops=whiskerprops,
2627-
manage_xticks=manage_xticks, data=data)
2628+
manage_xticks=manage_xticks, autorange=autorange,
2629+
zorder=zorder, data=data)
26282630
finally:
26292631
ax.hold(washold)
26302632

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

28212823
if hold is not None:
28222824
ax.hold(hold)
28232825
try:
2824-
ret = ax.fill_betweenx(y, x1, x2=x2, where=where, step=step, data=data,
2825-
**kwargs)
2826+
ret = ax.fill_betweenx(y, x1, x2=x2, where=where, step=step,
2827+
interpolate=interpolate, data=data, **kwargs)
28262828
finally:
28272829
ax.hold(washold)
28282830

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

37243727

3725-
# This function was autogenerated by boilerplate.py. Do not edit as
3726-
# changes will be lost
3727-
def spectral():
3728-
'''
3729-
set the default colormap to spectral and apply to current image if any.
3730-
See help(colormaps) for more information
3731-
'''
3732-
rc('image', cmap='spectral')
3733-
im = gci()
3734-
3735-
if im is not None:
3736-
im.set_cmap(cm.spectral)
3737-
3738-
37393728
# This function was autogenerated by boilerplate.py. Do not edit as
37403729
# changes will be lost
37413730
def magma():
@@ -3791,4 +3780,39 @@ def viridis():
37913780
if im is not None:
37923781
im.set_cmap(cm.viridis)
37933782

3783+
3784+
# This function was autogenerated by boilerplate.py. Do not edit as
3785+
# changes will be lost
3786+
def nipy_spectral():
3787+
'''
3788+
set the default colormap to nipy_spectral and apply to current image if any.
3789+
See help(colormaps) for more information
3790+
'''
3791+
rc('image', cmap='nipy_spectral')
3792+
im = gci()
3793+
3794+
if im is not None:
3795+
im.set_cmap(cm.nipy_spectral)
3796+
3797+
3798+
# This function was autogenerated by boilerplate.py. Do not edit as
3799+
# changes will be lost
3800+
def spectral():
3801+
'''
3802+
set the default colormap to spectral and apply to current image if any.
3803+
See help(colormaps) for more information
3804+
'''
3805+
from matplotlib.cbook import warn_deprecated
3806+
warn_deprecated(
3807+
"2.0",
3808+
name="spectral",
3809+
obj_type="colormap"
3810+
)
3811+
3812+
rc('image', cmap='spectral')
3813+
im = gci()
3814+
3815+
if im is not None:
3816+
im.set_cmap(cm.spectral)
3817+
37943818
_setup_pyplot_info_docstrings()

‎lib/mpl_toolkits/tests/test_axes_grid.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/tests/test_axes_grid.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_imagegrid_cbar_mode_edge():
2929
cbar_mode='edge')
3030
ax1, ax2, ax3, ax4, = grid
3131

32-
im1 = ax1.imshow(arr.real, cmap='spectral')
32+
im1 = ax1.imshow(arr.real, cmap='nipy_spectral')
3333
im2 = ax2.imshow(arr.imag, cmap='hot')
3434
im3 = ax3.imshow(np.abs(arr), cmap='jet')
3535
im4 = ax4.imshow(np.arctan2(arr.imag, arr.real), cmap='hsv')

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.