Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small improvements #284

Merged
merged 4 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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