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

RF: Consistently use matplotlib.colormaps in mpl namespace #104

Merged
merged 1 commit into from
May 8, 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
6 changes: 3 additions & 3 deletions nireports/reportlets/modality/dwi.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#
"""Visualizations for diffusion MRI data."""
import numpy as np
import matplotlib as mpl
from matplotlib import pyplot as plt
from matplotlib.pyplot import cm
from mpl_toolkits.mplot3d import art3d


Expand Down Expand Up @@ -258,7 +258,7 @@ def draw_points(gradients, ax, rad_min=0.3, rad_max=0.7, colormap="viridis"):
Minimum radius of the circle that renders a gradient direction.
rad_max : :obj:`float` between 0 and 1
Maximum radius of the circle that renders a gradient direction.
colormap : :obj:`matplotlib.pyplot.cm.ColorMap`
colormap : :class:`str`
matplotlib colormap name.

"""
Expand All @@ -273,7 +273,7 @@ def draw_points(gradients, ax, rad_min=0.3, rad_max=0.7, colormap="viridis"):
bvals = bvals / bvals.max()

# Colormap depending on bvalue (for visualization)
cmap = cm.get_cmap(colormap)
cmap = mpl.colormaps[colormap]
colors = cmap(bvals)

# Relative shell radii proportional to the inverse of bvalue (for visualization)
Expand Down
10 changes: 4 additions & 6 deletions nireports/reportlets/mosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import math
import numpy as np
import nibabel as nb
from matplotlib import colormaps
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
from svgutils.transform import fromstring
Expand Down Expand Up @@ -269,7 +269,7 @@
annotate=None,
):
if isinstance(cmap, (str, bytes)):
cmap = colormaps[cmap]
cmap = mpl.colormaps[cmap]

est_vmin, est_vmax = _get_limits(dslice)
if not vmin:
Expand Down Expand Up @@ -359,7 +359,7 @@
):

if isinstance(cmap, (str, bytes)):
cmap = colormaps[cmap]
cmap = mpl.colormaps[cmap]

Check warning on line 362 in nireports/reportlets/mosaic.py

View check run for this annotation

Codecov / codecov/patch

nireports/reportlets/mosaic.py#L362

Added line #L362 was not covered by tests

est_vmin, est_vmax = _get_limits(dslice)
if not vmin:
Expand Down Expand Up @@ -665,9 +665,7 @@
)

if overlay_mask:
from matplotlib import cm

msk_cmap = cm.Reds # @UndefinedVariable
msk_cmap = mpl.colormaps['Reds']

Check warning on line 668 in nireports/reportlets/mosaic.py

View check run for this annotation

Codecov / codecov/patch

nireports/reportlets/mosaic.py#L668

Added line #L668 was not covered by tests
msk_cmap._init()
alphas = np.linspace(0, 0.75, msk_cmap.N + 3)
msk_cmap._lut[:, -1] = alphas
Expand Down
10 changes: 5 additions & 5 deletions nireports/reportlets/nuisance.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import os.path as op

import numpy as np
from matplotlib import colormaps
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib.backends.backend_pdf import FigureCanvasPdf as FigureCanvas
Expand Down Expand Up @@ -274,9 +274,9 @@
legend = False

if cmap is None:
colors = colormaps["tab10"].colors
colors = mpl.colormaps["tab10"].colors
elif cmap == "paired":
colors = list(colormaps["Paired"].colors)
colors = list(mpl.colormaps["Paired"].colors)
colors[0], colors[1] = colors[1], colors[0]
colors[2], colors[7] = colors[7], colors[2]

Expand Down Expand Up @@ -469,7 +469,7 @@
ntsteps = ts_z.shape[1]

# Load a colormap
my_cmap = colormaps[cmap]
my_cmap = mpl.colormaps[cmap]

Check warning on line 472 in nireports/reportlets/nuisance.py

View check run for this annotation

Codecov / codecov/patch

nireports/reportlets/nuisance.py#L472

Added line #L472 was not covered by tests
norm = Normalize(vmin=0, vmax=float(nslices - 1))
colors = [my_cmap(norm(sl)) for sl in range(nslices)]

Expand Down Expand Up @@ -597,7 +597,7 @@
cax = fig.add_axes(position)
cb = ColorbarBase(
cax,
cmap=colormaps[cmap],
cmap=mpl.colormaps[cmap],
spacing="proportional",
orientation="horizontal",
drawedges=False,
Expand Down
Loading