Skip to content

Commit 6061a43

Browse files
authored
Merge pull request #7982 from QuLogic/fix-spectral-deprecation
Backport spectral/spectral_r deprecations fixes from #7857
2 parents 9b177a9 + 0017d3e commit 6061a43

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

lib/matplotlib/cm.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import six
1111

1212
import os
13-
import warnings as _warnings # To remove once spectral is removed
1413
import numpy as np
1514
from numpy import ma
1615
import matplotlib as mpl
@@ -69,7 +68,8 @@ def _generate_cmap(name, lutsize):
6968
"""Generates the requested cmap from its *name*. The lut size is
7069
*lutsize*."""
7170

72-
spec = datad[name]
71+
# Use superclass method to avoid deprecation warnings during initial load.
72+
spec = dict.__getitem__(datad, name)
7373

7474
# Generate the colormap object.
7575
if 'red' in spec:
@@ -81,22 +81,18 @@ def _generate_cmap(name, lutsize):
8181

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

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)
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
93+
# above:
94+
for cmapname in six.iterkeys(datad):
95+
cmap_d[cmapname] = _generate_cmap(cmapname, LUTSIZE)
10096

10197
cmap_d.update(cmaps_listed)
10298

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy