diff --git a/glue_jupyter/state_traitlets_helpers.py b/glue_jupyter/state_traitlets_helpers.py index f76a4405..d4f39862 100644 --- a/glue_jupyter/state_traitlets_helpers.py +++ b/glue_jupyter/state_traitlets_helpers.py @@ -4,9 +4,13 @@ from traitlets.utils.bunch import Bunch from glue.core.state_objects import State from glue.core import BaseCartesianData, Subset, ComponentID +from glue.utils.matplotlib import MATPLOTLIB_GE_36 from echo import CallbackList, CallbackDict from matplotlib.colors import Colormap -from matplotlib.cm import get_cmap +if MATPLOTLIB_GE_36: + from matplotlib import colormaps +else: + from matplotlib import cm as colormaps MAGIC_IGNORE = '611cfa3b-ebb5-42d2-b5c7-ba9bce8b51a4' @@ -74,7 +78,7 @@ def update_state_from_dict(state, changes): if changes[name] != MAGIC_IGNORE and getattr(state, name) != changes[name]: if name == 'cmap': if changes[name] != state.cmap.name: - setattr(state, name, get_cmap(changes[name])) + setattr(state, name, colormaps.get_cmap(changes[name])) else: setattr(state, name, changes[name]) diff --git a/glue_jupyter/utils.py b/glue_jupyter/utils.py index c2479235..e77ab8dd 100644 --- a/glue_jupyter/utils.py +++ b/glue_jupyter/utils.py @@ -2,14 +2,19 @@ import functools import collections import time +from io import BytesIO as StringIO import ipyvue -import matplotlib import PIL.Image import numpy as np -from io import BytesIO as StringIO from glue.core import BaseCartesianData +from glue.utils.matplotlib import MATPLOTLIB_GE_36 + +if MATPLOTLIB_GE_36: + from matplotlib import colormaps +else: + from matplotlib import cm as colormaps def float_or_none(x): @@ -27,7 +32,7 @@ def rgba_to_png_data(rgba): def scalar_to_png_data(data, colormap='viridis'): mask = ~np.isfinite(data) intensity = np.ma.masked_array(data, mask) - colormap = matplotlib.cm.get_cmap(colormap) + colormap = colormaps.get_cmap(colormap) colormap.set_bad(alpha=0) data = colormap(intensity, bytes=True) return rgba_to_png_data(data)