From 36ee87aae414214f610851d815e5f968dc47668f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dav=C3=ADd=20Brakenhoff?= Date: Thu, 2 Nov 2023 17:44:39 +0100 Subject: [PATCH 1/4] support custom extent in _get_figure --- nlmod/plot/plot.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/nlmod/plot/plot.py b/nlmod/plot/plot.py index f581ff78..4979b17a 100644 --- a/nlmod/plot/plot.py +++ b/nlmod/plot/plot.py @@ -282,20 +282,21 @@ def geotop_lithok_in_cross_section( return cs -def _get_figure(ax=None, da=None, ds=None, figsize=None, rotated=True): +def _get_figure(ax=None, da=None, ds=None, figsize=None, rotated=True, extent=None): # figure if ax is not None: f = ax.figure else: - if ds is None: - extent = [ - da.x.values.min(), - da.x.values.max(), - da.y.values.min(), - da.y.values.max(), - ] - else: - extent = get_extent(ds, rotated=rotated) + if extent is None: + if ds is None: + extent = [ + da.x.values.min(), + da.x.values.max(), + da.y.values.min(), + da.y.values.max(), + ] + else: + extent = get_extent(ds, rotated=rotated) if figsize is None: figsize = get_figsize(extent) @@ -377,7 +378,9 @@ def map_array( else: t = None - f, ax = _get_figure(ax=ax, da=da, ds=ds, figsize=figsize, rotated=rotated) + f, ax = _get_figure( + ax=ax, da=da, ds=ds, figsize=figsize, rotated=rotated, extent=extent + ) # get normalization if vmin/vmax are passed if vmin is not None or vmax is not None: From 6bfa587a9380f767c64a12658e584c0edd2d539b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dav=C3=ADd=20Brakenhoff?= Date: Thu, 2 Nov 2023 17:45:05 +0100 Subject: [PATCH 2/4] respect user provided extent, even when plotting model grid --- nlmod/plot/plot.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nlmod/plot/plot.py b/nlmod/plot/plot.py index 4979b17a..79e5f6ea 100644 --- a/nlmod/plot/plot.py +++ b/nlmod/plot/plot.py @@ -391,10 +391,6 @@ def map_array( da, ds=ds, cmap=cmap, alpha=alpha, norm=norm, ax=ax, rotated=rotated ) - # set extent - if extent is not None: - ax.axis(extent) - # bgmap if background: add_background_map(ax, map_provider="nlmaps.water", alpha=0.5) @@ -410,6 +406,10 @@ def map_array( raise ValueError("Plotting modelgrid requires model Dataset!") modelgrid(ds, ax=ax, lw=0.25, alpha=0.5, color="k") + # set extent + if extent is not None: + ax.axis(extent) + # axes properties if ilay is not None: title += f" (layer={layer})" From 6bbb0f7d60aae38fac305f26d7a89e85b5ef4105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dav=C3=ADd=20Brakenhoff?= Date: Thu, 2 Nov 2023 17:45:44 +0100 Subject: [PATCH 3/4] allow controlling colorbar extending through extend kwarg in map_array --- nlmod/plot/plot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nlmod/plot/plot.py b/nlmod/plot/plot.py index 79e5f6ea..bfec9cf2 100644 --- a/nlmod/plot/plot.py +++ b/nlmod/plot/plot.py @@ -338,6 +338,7 @@ def map_array( background=False, figsize=None, animate=False, + **kwargs, ): # get data if isinstance(da, str): @@ -424,7 +425,7 @@ def map_array( divider = make_axes_locatable(ax) if colorbar: cax = divider.append_axes("right", size="5%", pad=0.1) - cbar = f.colorbar(pc, cax=cax) + cbar = f.colorbar(pc, cax=cax, extend=kwargs.pop("extend", "neither")) if levels is not None: cbar.set_ticks(levels) cbar.set_label(colorbar_label) From 86ba2755b08f6c889a99dd5a9f02af5c49750843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dav=C3=ADd=20Brakenhoff?= Date: Thu, 2 Nov 2023 17:45:55 +0100 Subject: [PATCH 4/4] typo --- nlmod/dims/resample.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nlmod/dims/resample.py b/nlmod/dims/resample.py index 50a17cfe..6efa7780 100644 --- a/nlmod/dims/resample.py +++ b/nlmod/dims/resample.py @@ -407,7 +407,7 @@ def vertex_da_to_ds(da, ds, method="nearest"): # when there are more dimensions than icell2d z = [] if method == "nearest": - # geneterate the tree only once, to increase speed + # generate the tree only once, to increase speed tree = cKDTree(points) _, i = tree.query(xi) dims = np.array(da.dims)