Skip to content

Commit

Permalink
Merge fca4c96 into a54cf2a
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahclaude committed Apr 3, 2024
2 parents a54cf2a + fca4c96 commit 3ee9630
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ Changelog

0.4.0 (unreleased)
------------------
Contributors to this version: Trevor James Smith (:user:`Zeitsperre`), Marco Braun (:user:`vindelico`)
Contributors to this version: Trevor James Smith (:user:`Zeitsperre`), Marco Braun (:user:`vindelico`), Sarah-Claude Bourdeau-Goulet (:user:`Sarahclaude`)

New features and enhancements
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* Use list or ndarray as levels for colorbar in gridmap and small bug fixes (:pull:`176`).
* Fix NaN issues in ``fg.matplotlib.scattermap`` and extreme values in sizes legend (:pull:`184`).

Internal changes
^^^^^^^^^^^^^^^^
Expand Down
9 changes: 7 additions & 2 deletions docs/notebooks/figanos_docs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,10 @@
"lat = 45 + np.random.rand(10)*3\n",
"lon = np.linspace(-76,-70, 10)\n",
"tas = 20 + np.random.rand(10)*7\n",
"yrs = (30 * np.random.rand(10)).astype(int)\n",
"tas[9] = np.nan\n",
"yrs = (10+30 * np.random.rand(10))\n",
"yrs[0] = np.nan\n",
"\n",
"attrs = {'units': 'degC', 'standard_name': 'air_temperature', 'long_name': 'Near-Surface Daily Maximum Air Temperature'}\n",
"\n",
"tas = xr.DataArray(data=tas,\n",
Expand Down Expand Up @@ -659,7 +662,9 @@
" features=features,\n",
" plot_kw={\n",
" \"xlim\": (-78,-68),\n",
" \"ylim\": (43,50)},\n",
" \"ylim\": (43,50),\n",
" \"edgecolor\": 'black'\n",
" },\n",
" fig_kw={'figsize': (9,6)},\n",
" legend_kw={'loc': 'lower left',\n",
" 'title': 'Number of years of data'},\n",
Expand Down
11 changes: 6 additions & 5 deletions figanos/matplotlib/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,7 @@ def scattermap(
if hasattr(data, "name") and getattr(data, "name") == sizes:
sdata = plot_data
elif sizes in list(data.coords.keys()):
sdata = data[sizes]
sdata = plot_data[sizes]
else:
raise ValueError(f"{sizes} not found")
else:
Expand All @@ -1650,7 +1650,7 @@ def scattermap(
mask = smask

pt_sizes = norm2range(
data=sdata.values,
data=sdata.where(mask).values,
target_range=size_range,
data_range=None,
)
Expand All @@ -1661,8 +1661,8 @@ def scattermap(
plot_kw.setdefault("s", pt_sizes[0])

# norm
plot_kw.setdefault("vmin", np.nanmin(plot_data.values))
plot_kw.setdefault("vmax", np.nanmax(plot_data.values))
plot_kw.setdefault("vmin", np.nanmin(plot_data.values[mask]))
plot_kw.setdefault("vmax", np.nanmax(plot_data.values[mask]))

norm = custom_cmap_norm(
cmap,
Expand All @@ -1689,7 +1689,8 @@ def scattermap(
plot_kw_pop = {"x": "lon", "y": "lat", "hue": plot_data.name} | plot_kw_pop
if ax:
plot_kw_pop.setdefault("ax", ax)
im = data.plot.scatter(**plot_kw_pop)
v = plot_data.where(mask).to_dataset()
im = v.plot.scatter(**plot_kw_pop)

# add features
if ax:
Expand Down
2 changes: 1 addition & 1 deletion figanos/matplotlib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ def size_legend_elements(
lw=0,
markerfacecolor="w",
label=label,
markersize=np.sqrt(s),
markersize=np.sqrt(np.abs(s)),
)
)

Expand Down

0 comments on commit 3ee9630

Please sign in to comment.