From f2e6231c720fcbc040ee3d23657b978555eb400e Mon Sep 17 00:00:00 2001 From: juliettelavoie Date: Wed, 7 Aug 2024 10:03:32 -0400 Subject: [PATCH 1/2] use gridmap code --- CHANGELOG.rst | 5 +++++ src/figanos/matplotlib/plot.py | 38 +++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index caf8ae9..a1d474f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -42,6 +42,11 @@ Internal changes * Maintainer-specific documentation has been added to new documentation page `releasing.rst`. * `figanos` now has a `CODE_OF_CONDUCT.rst` file adapting the Contributor Covenant v2.1 conventions. (:pull:`210`). +Bug fixes +^^^^^^^^^ +* Creating the colormap in `fg.matplotlib.scattermap` is now done like `fg.matplotlib.gridmap` (:pull:`184`, :issue:`239`). + + 0.3.0 (2024-02-16) ------------------ Contributors to this version: Sarah-Claude Bourdeau-Goulet (:user:`Sarahclaude`), Pascal Bourgault (:user:`aulemahal`), Trevor James Smith (:user:`Zeitsperre`), Juliette Lavoie (:user:`juliettelavoie`), Gabriel Rondeau-Genesse (:user:`RondeauG`). diff --git a/src/figanos/matplotlib/plot.py b/src/figanos/matplotlib/plot.py index 060158e..9b5373b 100644 --- a/src/figanos/matplotlib/plot.py +++ b/src/figanos/matplotlib/plot.py @@ -1747,22 +1747,34 @@ def scattermap( else: plot_kw_pop.setdefault("s", pt_sizes[0]) - # norm - plot_kw_pop.setdefault("vmin", np.nanmin(plot_data.values[mask])) - plot_kw_pop.setdefault("vmax", np.nanmax(plot_data.values[mask])) - - norm = custom_cmap_norm( - cmap, - vmin=plot_kw_pop["vmin"], - vmax=plot_kw_pop["vmax"], - levels=levels, - divergent=divergent, - ) + if levels is not None: + if isinstance(levels, Iterable): + lin = levels + else: + lin = custom_cmap_norm( + cmap, + np.nanmin(plot_data.values[mask]), + np.nanmax(plot_data.values[mask]), + levels=levels, + divergent=divergent, + linspace_out=True, + ) + plot_kw_pop.setdefault("levels", lin) + + elif (divergent is not False) and ("levels" not in plot_kw): + norm = custom_cmap_norm( + cmap, + np.nanmin(plot_data.values[mask]), + np.nanmax(plot_data.values[mask]), + levels=levels, + divergent=divergent, + ) + plot_kw_pop.setdefault("norm", norm) # set defaults and create copy without vmin, vmax (conflicts with norm) plot_kw_pop = { "cmap": cmap, - "norm": norm, + # "norm": norm, "transform": transform, "zorder": 8, "marker": "o", @@ -1788,8 +1800,6 @@ def scattermap( else: plot_kw_pop.setdefault("edgecolor", "none") - for key in ["vmin", "vmax"]: - plot_kw_pop.pop(key) # plot plot_kw_pop = {"x": "lon", "y": "lat", "hue": plot_data.name} | plot_kw_pop if ax: From 96a1d226b0e8aafb5c89b3ebae224228b912417c Mon Sep 17 00:00:00 2001 From: juliettelavoie Date: Wed, 7 Aug 2024 10:06:43 -0400 Subject: [PATCH 2/2] wrong number --- CHANGELOG.rst | 2 +- src/figanos/matplotlib/plot.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a1d474f..1f65d33 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -44,7 +44,7 @@ Internal changes Bug fixes ^^^^^^^^^ -* Creating the colormap in `fg.matplotlib.scattermap` is now done like `fg.matplotlib.gridmap` (:pull:`184`, :issue:`239`). +* Creating the colormap in `fg.matplotlib.scattermap` is now done like `fg.matplotlib.gridmap` (:pull:`238`, :issue:`239`). 0.3.0 (2024-02-16) diff --git a/src/figanos/matplotlib/plot.py b/src/figanos/matplotlib/plot.py index 9b5373b..ecf97a5 100644 --- a/src/figanos/matplotlib/plot.py +++ b/src/figanos/matplotlib/plot.py @@ -1771,10 +1771,9 @@ def scattermap( ) plot_kw_pop.setdefault("norm", norm) - # set defaults and create copy without vmin, vmax (conflicts with norm) + # set defaults and plot_kw_pop = { "cmap": cmap, - # "norm": norm, "transform": transform, "zorder": 8, "marker": "o",