Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use mpl.colormaps.get_cmap for compatibility with matplotlib 3.9 #422

Merged
merged 4 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions glue_jupyter/state_traitlets_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 13 in glue_jupyter/state_traitlets_helpers.py

View check run for this annotation

Codecov / codecov/patch

glue_jupyter/state_traitlets_helpers.py#L13

Added line #L13 was not covered by tests

MAGIC_IGNORE = '611cfa3b-ebb5-42d2-b5c7-ba9bce8b51a4'

Expand Down Expand Up @@ -74,7 +78,7 @@
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]))

Check warning on line 81 in glue_jupyter/state_traitlets_helpers.py

View check run for this annotation

Codecov / codecov/patch

glue_jupyter/state_traitlets_helpers.py#L81

Added line #L81 was not covered by tests
else:
setattr(state, name, changes[name])

Expand Down
11 changes: 8 additions & 3 deletions glue_jupyter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 17 in glue_jupyter/utils.py

View check run for this annotation

Codecov / codecov/patch

glue_jupyter/utils.py#L17

Added line #L17 was not covered by tests


def float_or_none(x):
Expand All @@ -27,7 +32,7 @@
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)

Check warning on line 35 in glue_jupyter/utils.py

View check run for this annotation

Codecov / codecov/patch

glue_jupyter/utils.py#L35

Added line #L35 was not covered by tests
colormap.set_bad(alpha=0)
data = colormap(intensity, bytes=True)
return rgba_to_png_data(data)
Expand Down
Loading