From 9c1e32d2bc25ca71e8777d1573698e51237e3bcf Mon Sep 17 00:00:00 2001 From: Chris Fairless Date: Sat, 10 Oct 2026 02:11:44 +0200 Subject: [PATCH 1/2] Bugfix forced log scales in raster plots --- climada/entity/exposures/base.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/climada/entity/exposures/base.py b/climada/entity/exposures/base.py index 1989e0fd8..a3ac642e6 100644 --- a/climada/entity/exposures/base.py +++ b/climada/entity/exposures/base.py @@ -964,7 +964,7 @@ def plot_raster( res=None, raster_res=None, save_tiff=None, - raster_f=lambda x: np.log10((np.fmax(x + 1, 1))), + raster_f=lambda x: np.log10((np.maximum(x + 1, 1))), label="value (log10)", scheduler=None, axis=None, @@ -974,7 +974,7 @@ def plot_raster( **kwargs, ): """Generate raster from points geometry and plot it using log10 scale - `np.log10((np.fmax(raster+1, 1)))`. + `np.log10((np.maximum(raster+1, 1)))`. Parameters ---------- @@ -1001,6 +1001,8 @@ def plot_raster( fill : bool, optional If false, the areas with no data will be plotted in white. If True, the areas with missing values are filled as 0s. + Zero-valued raster cells are treated as missing and masked after + applying raster_f when fill is False. The default is True. adapt_fontsize : bool, optional If set to true, the size of the fonts will be adapted to the size of the figure. @@ -1065,13 +1067,13 @@ def plot_raster( ) axis.set_extent((xmin, xmax, ymin, ymax), crs=proj_data) u_plot.add_shapes(axis) + raster_plot = raster_f(raster) if not fill: - raster = np.where(raster == 0, np.nan, raster) - raster_f = lambda x: np.log10((np.maximum(x + 1, 1))) + raster_plot = np.where(raster == 0, np.nan, raster_plot) if "cmap" not in kwargs: kwargs["cmap"] = CMAP_RASTER imag = axis.imshow( - raster_f(raster), + raster_plot, **kwargs, origin="upper", extent=(xmin, xmax, ymin, ymax), From a75a1f158fcfd3bf7ac5b689ef162d1ea543346c Mon Sep 17 00:00:00 2001 From: Chris Fairless Date: Sat, 10 Oct 2026 02:55:05 +0200 Subject: [PATCH 2/2] fixup and clarify --- climada/entity/exposures/base.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/climada/entity/exposures/base.py b/climada/entity/exposures/base.py index a3ac642e6..f4f9af26b 100644 --- a/climada/entity/exposures/base.py +++ b/climada/entity/exposures/base.py @@ -964,7 +964,7 @@ def plot_raster( res=None, raster_res=None, save_tiff=None, - raster_f=lambda x: np.log10((np.maximum(x + 1, 1))), + raster_f=lambda x: np.log10((np.fmax(x + 1, 1))), label="value (log10)", scheduler=None, axis=None, @@ -974,7 +974,7 @@ def plot_raster( **kwargs, ): """Generate raster from points geometry and plot it using log10 scale - `np.log10((np.maximum(raster+1, 1)))`. + `np.log10((np.fmax(raster+1, 1)))`. Parameters ---------- @@ -999,11 +999,9 @@ def plot_raster( figsize : tuple, optional figure size for plt.subplots fill : bool, optional - If false, the areas with no data will be plotted - in white. If True, the areas with missing values are filled as 0s. - Zero-valued raster cells are treated as missing and masked after - applying raster_f when fill is False. - The default is True. + If false, the areas with no data or zero value will be plotted + in white. If True, missing values are filled as 0s and plotted + with the corresponding colour. The default is True. adapt_fontsize : bool, optional If set to true, the size of the fonts will be adapted to the size of the figure. Otherwise the default matplotlib font size is used. Default is True. @@ -1069,7 +1067,7 @@ def plot_raster( u_plot.add_shapes(axis) raster_plot = raster_f(raster) if not fill: - raster_plot = np.where(raster == 0, np.nan, raster_plot) + raster_plot = np.where((raster == 0) | np.isnan(raster), np.nan, raster_plot) if "cmap" not in kwargs: kwargs["cmap"] = CMAP_RASTER imag = axis.imshow(