From 23f52a8d4303ffe043948fb195607c7eeae00305 Mon Sep 17 00:00:00 2001 From: knaaptime Date: Sun, 5 Jan 2025 22:06:46 -0800 Subject: [PATCH] tab20 as default for cats --- geosnap/visualize/interactive.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/geosnap/visualize/interactive.py b/geosnap/visualize/interactive.py index f81b9601..66c7301e 100644 --- a/geosnap/visualize/interactive.py +++ b/geosnap/visualize/interactive.py @@ -262,7 +262,7 @@ def _dexplore( f"`cmap` must be one of {list(colormaps.keys())} but {cmap} was passed" ) if cmap is None: - cmap = "Set1" if categorical else "viridis" + cmap = "tab20" if categorical else "viridis" if categorical: color_array = _get_categorical_cmap(gdf[column], cmap, nan_color, alpha) elif scheme is None: @@ -313,21 +313,15 @@ def _get_categorical_cmap(categories, cmap, nan_color, alpha): ) from e cat_codes = pd.Series(pd.Categorical(categories).codes, dtype="category") - # nans are encoded as -1 OR largest category depending on input type # re-encode to always be last category cat_codes = cat_codes.cat.rename_categories({-1: len(cat_codes.unique()) - 1}) - unique_cats = categories.dropna().unique() n_cats = len(unique_cats) - colors = colormaps[cmap].resampled(n_cats)(list(range(n_cats)), alpha) colors = (np.array(colors) * 255).astype(int) colors = np.vstack([colors, nan_color]) - - n_colors = colors.shape[0] - if n_cats > n_colors: warn( "the number of unique categories exceeds the number of available colors", @@ -335,7 +329,6 @@ def _get_categorical_cmap(categories, cmap, nan_color, alpha): ) floor = (n_cats // n_colors) + 1 colors = np.vstack([colors] * floor) - temp_cmap = dict(zip(range(n_cats + 1), colors)) fill_color = apply_categorical_cmap(cat_codes, temp_cmap) return fill_color