Skip to content

Commit

Permalink
Merge pull request #284 from gwmod/small-improvements
Browse files Browse the repository at this point in the history
Small improvements
  • Loading branch information
dbrakenhoff authored Nov 3, 2023
2 parents 4ad10b0 + 86ba275 commit 91ad942
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion nlmod/dims/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 20 additions & 16 deletions nlmod/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -337,6 +338,7 @@ def map_array(
background=False,
figsize=None,
animate=False,
**kwargs,
):
# get data
if isinstance(da, str):
Expand Down Expand Up @@ -377,7 +379,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:
Expand All @@ -388,10 +392,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)
Expand All @@ -407,6 +407,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})"
Expand All @@ -421,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)
Expand Down

0 comments on commit 91ad942

Please sign in to comment.