From ab5076e9ca7d59b44470ccdb4f8eb922a05da99a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ruben=20Calj=C3=A9?= Date: Thu, 17 Apr 2025 09:36:13 +0200 Subject: [PATCH] improve plot.data_array for structured grids --- nlmod/plot/plot.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/nlmod/plot/plot.py b/nlmod/plot/plot.py index c165c3aa..9ffff540 100644 --- a/nlmod/plot/plot.py +++ b/nlmod/plot/plot.py @@ -18,6 +18,8 @@ get_extent, get_extent_gdf, modelgrid_from_ds, + get_delr, + get_delc, ) from ..read import geotop, rws from .dcs import DatasetCrossSection @@ -250,15 +252,26 @@ def data_array(da, ds=None, ax=None, rotated=False, edgecolor=None, **kwargs): ax.axis(extent) return pc else: - x = da.x - y = da.y + if ds is None: + x = da.x + y = da.y + shading = "nearest" + else: + x = ds["x"].values + dx = get_delr(ds) + x = np.hstack((x - dx / 2, x[-1] + dx[-1] / 2)) + + y = ds["y"].values + dy = get_delc(ds) + y = np.hstack((y + dy / 2, y[-1] - dy[-1] / 2)) + shading = "flat" if rotated: if ds is None: raise (ValueError("Supply model dataset (ds) for grid information")) if "angrot" in ds.attrs and ds.attrs["angrot"] != 0.0: affine = get_affine_mod_to_world(ds) x, y = affine * np.meshgrid(x, y) - return ax.pcolormesh(x, y, da, shading="nearest", edgecolor=edgecolor, **kwargs) + return ax.pcolormesh(x, y, da, shading=shading, edgecolor=edgecolor, **kwargs) def geotop_lithok_in_cross_section(