diff --git a/hvplot/converter.py b/hvplot/converter.py index 9f15b40d6..0d225a94a 100644 --- a/hvplot/converter.py +++ b/hvplot/converter.py @@ -76,7 +76,7 @@ process_derived_datetime_pandas, _convert_col_names_to_str, import_datashader, - _mpl_cmap, + is_mpl_cmap, ) from .utilities import hvplot_extension @@ -1486,8 +1486,12 @@ def _process_style(self, kwds, plot_opts): if 'color' in style_opts: color = style_opts['color'] elif not isinstance(cmap, dict): - if (isinstance(cmap, str) or _mpl_cmap(cmap)) and any( - c in getattr(cmap, 'name', cmap) for c in categorical_cmaps + # Checks if any of the categorical cmaps matches cmap; + # uses any() instead of `cmap in categorical_cmaps` to handle reversed colormaps (suffixed with `_r`). + # If cmap is LinearSegmentedColormap, get the name attr, else return the str typed cmap. + if (isinstance(cmap, str) or is_mpl_cmap(cmap)) and any( + categorical_cmap in getattr(cmap, 'name', cmap) + for categorical_cmap in categorical_cmaps ): color = process_cmap(cmap or self._default_cmaps['categorical'], categorical=True) else: diff --git a/hvplot/util.py b/hvplot/util.py index 7c4c74661..db347c608 100644 --- a/hvplot/util.py +++ b/hvplot/util.py @@ -752,7 +752,7 @@ def relabel_redim(hv_obj, relabel_kwargs, redim_kwargs): return hv_obj -def _mpl_cmap(obj): +def is_mpl_cmap(obj): """Check if the object is a Matplotlib LinearSegmentedColormap.""" if 'matplotlib' not in sys.modules: return False