Skip to content
Open
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
27 changes: 20 additions & 7 deletions src/MNHPy/Panel_Plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,28 @@
import matplotlib as mpl
# mpl.use('Agg')
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.colors import ListedColormap
from matplotlib.colors import Colormap, ListedColormap
import numpy as np
import cartopy
import cartopy.feature as cfeature


def get_cmap(colormap_in, lut):
"""Return colormap_in resampled to lut colors

Replaces matplotlib.cm.get_cmap(name, lut), deprecated in Matplotlib 3.7
and removed in 3.11. Both special cases of the original are kept: None
means the rcParams default, and a Colormap instance is returned unchanged.
resampled() returns a new object, so the caller may mutate it without
touching the registered colormap.
"""
if colormap_in is None:
colormap_in = mpl.rcParams['image.cmap']
if isinstance(colormap_in, Colormap):
return colormap_in
return mpl.colormaps[colormap_in].resampled(lut)


class PanelPlot():

def __init__(self, nb_l, nb_c, Lfigsize, bigtitle, bigtitlepad=0.95, titlepad=40, minmaxpad=1.03, timepad=-0.06, lateralminmaxpad=0.86,
Expand Down Expand Up @@ -111,7 +126,7 @@ def addWhitecm(self, colormap_in, nb_level, whiteTop=False):
"""
Add a white color at the top (whiteTop=True) or bottom of the colormap w.r.t. the number of independent colors used
"""
color_map = cm.get_cmap(colormap_in, 256)
color_map = get_cmap(colormap_in, 256)
newcolor_map = color_map(np.linspace(0, 1, 256))
whites = np.array([1, 1, 1, 1]) # RBG code + opacity
if whiteTop:
Expand All @@ -127,11 +142,9 @@ def addColorcm(self, colormap_in):
"""
Assign the last color of the colormap to the values out of range
"""
colormap = cm.get_cmap(colormap_in, 256)
colormap = get_cmap(colormap_in, 256)

colormap.set_under(color=colormap(1./256))
colormap.set_over(color=colormap(1.-1./256))
return(colormap)
return colormap.with_extremes(under=colormap(1./256), over=colormap(1.-1./256))

def set_Title(self, ax, i, title, Lid_overlap, xlab, ylab):
"""
Expand Down