Commit c094d23d authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

MNT: Don't use matplotlib.cm.cmap_d

parent a811c494
......@@ -193,8 +193,11 @@ import logging
import sys
import argparse
from . import properties as props
from . import properties_types as ptypes
import matplotlib.pyplot as plt
import matplotlib.cm as mplcm
import fsleyes_props.properties as props
import fsleyes_props.properties_types as ptypes
log = logging.getLogger(__name__)
......@@ -205,7 +208,6 @@ class SkipArgument(Exception):
by :func:`applyArguments` and :func:`generateArguments` to indicate
that the arguemnt should be skipped (i.e. not applied, or not generated).
"""
pass
def _String(parser,
......@@ -480,24 +482,21 @@ def _ColourMap(parser,
def parse(cmapName):
try:
import matplotlib.cm as mplcm
cmapKeys = list(mplcm.cmap_d.keys())
cmapNames = [mplcm.cmap_d[k].name for k in cmapKeys]
cmapKeys = plt.colormaps()
cmapNames = [mplcm.get_cmap(cm).name for cm in cmapKeys]
lCmapNames = [s.lower() for s in cmapNames]
lCmapKeys = [s.lower() for s in cmapKeys]
cmapName = cmapName.lower()
try: idx = lCmapKeys .index(cmapName)
except: idx = lCmapNames.index(cmapName)
except ValueError: idx = lCmapNames.index(cmapName)
cmapName = cmapKeys[idx]
return mplcm.get_cmap(cmapName)
except:
except Exception:
raise argparse.ArgumentTypeError(
'Unknown colour map: {}'.format(cmapName))
......
......@@ -33,8 +33,8 @@ added as attributes of a :class:`.HasProperties` class definition.
import os.path as op
from collections import abc
import matplotlib.pyplot as plt
import matplotlib.cm as mplcm
import matplotlib.colors as mplcolors
import numpy as np
......@@ -892,7 +892,6 @@ class ColourMap(props.PropertyBase):
matplotlib :class:`.Colormap` instance.
"""
import matplotlib.colors as mplcolors
if not isinstance(value, mplcolors.Colormap):
raise ValueError('Colour map value is not a '
'matplotlib.colors.Colormap instance')
......@@ -909,26 +908,19 @@ class ColourMap(props.PropertyBase):
if isinstance(value, str):
import matplotlib.cm as mplcm
# Case insensitive match
cmapKeys = list(mplcm.cmap_d.keys())
cmapNames = [cm.name for cm in mplcm.cmap_d.values()]
# Case insensitive match against either
# the registered colourmap key, or the
# colourmap name
cmapKeys = plt.colormaps()
cmapNames = [mplcm.get_cmap(cm).name for cm in cmapKeys]
lCmapNames = [s.lower() for s in cmapNames]
lCmapKeys = [s.lower() for s in cmapKeys]
value = value.lower()
try:
idx = lCmapKeys .index(value)
except ValueError:
idx = None
try:
idx = lCmapNames.index(value)
except ValueError:
idx = None
try: idx = lCmapKeys .index(value)
except ValueError: idx = lCmapNames.index(value)
if idx is None:
raise ValueError('Unknown colour map ({}) - valid choices '
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment