From cc92be4e4587a380c81a8a6e9abba27a7ebbb972 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Wed, 8 May 2024 09:30:45 -0400 Subject: [PATCH] RF: Consistently use matplotlib.colormaps in mpl namespace --- nireports/reportlets/modality/dwi.py | 6 +++--- nireports/reportlets/mosaic.py | 10 ++++------ nireports/reportlets/nuisance.py | 10 +++++----- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/nireports/reportlets/modality/dwi.py b/nireports/reportlets/modality/dwi.py index 7c1d7b5a..3aa80d97 100644 --- a/nireports/reportlets/modality/dwi.py +++ b/nireports/reportlets/modality/dwi.py @@ -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 @@ -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. """ @@ -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) diff --git a/nireports/reportlets/mosaic.py b/nireports/reportlets/mosaic.py index d8d0e213..b098890c 100644 --- a/nireports/reportlets/mosaic.py +++ b/nireports/reportlets/mosaic.py @@ -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 @@ -269,7 +269,7 @@ def plot_slice( annotate=None, ): if isinstance(cmap, (str, bytes)): - cmap = colormaps[cmap] + cmap = mpl.colormaps[cmap] est_vmin, est_vmax = _get_limits(dslice) if not vmin: @@ -359,7 +359,7 @@ def plot_slice_tern( ): if isinstance(cmap, (str, bytes)): - cmap = colormaps[cmap] + cmap = mpl.colormaps[cmap] est_vmin, est_vmax = _get_limits(dslice) if not vmin: @@ -665,9 +665,7 @@ def plot_mosaic( ) if overlay_mask: - from matplotlib import cm - - msk_cmap = cm.Reds # @UndefinedVariable + msk_cmap = mpl.colormaps['Reds'] msk_cmap._init() alphas = np.linspace(0, 0.75, msk_cmap.N + 3) msk_cmap._lut[:, -1] = alphas diff --git a/nireports/reportlets/nuisance.py b/nireports/reportlets/nuisance.py index 4027441e..9653780a 100644 --- a/nireports/reportlets/nuisance.py +++ b/nireports/reportlets/nuisance.py @@ -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 @@ -274,9 +274,9 @@ def plot_carpet( 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] @@ -469,7 +469,7 @@ def spikesplot( ntsteps = ts_z.shape[1] # Load a colormap - my_cmap = colormaps[cmap] + my_cmap = mpl.colormaps[cmap] norm = Normalize(vmin=0, vmax=float(nslices - 1)) colors = [my_cmap(norm(sl)) for sl in range(nslices)] @@ -597,7 +597,7 @@ def spikesplot_cb(position, cmap="viridis", fig=None): cax = fig.add_axes(position) cb = ColorbarBase( cax, - cmap=colormaps[cmap], + cmap=mpl.colormaps[cmap], spacing="proportional", orientation="horizontal", drawedges=False,