From 8d519b2b4753fcd50f59d7b3786713bddd985cf6 Mon Sep 17 00:00:00 2001 From: Frank Schultz Date: Tue, 16 Sep 2025 13:52:50 +0200 Subject: [PATCH 1/2] add colorbar label defaults if these kwargs are not submitted to level() and amplitude() --- sfs/plot2d.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sfs/plot2d.py b/sfs/plot2d.py index 2668aca5..abea658c 100644 --- a/sfs/plot2d.py +++ b/sfs/plot2d.py @@ -319,6 +319,7 @@ def amplitude(p, grid, *, xnorm=None, cmap='coolwarm_clip', ax.set_xlabel(xlabel) ax.set_ylabel(ylabel) if colorbar: + colorbar_kwargs.setdefault('label', 'relative pressure') add_colorbar(im, **colorbar_kwargs) return im @@ -339,6 +340,7 @@ def level(p, grid, *, xnorm=None, power=False, cmap=None, vmax=3, vmin=-50, if xnorm is not None: p = _util.normalize(p, grid, xnorm) L = _util.db(p, power=power) + kwargs.setdefault('colorbar_kwargs', {'label': 'level / dB'}) return amplitude(L, grid=grid, xnorm=None, cmap=cmap, vmax=vmax, vmin=vmin, **kwargs) From fd2e03f65d6d5398abd7a7af454483c550d715e4 Mon Sep 17 00:00:00 2001 From: Frank Schultz Date: Tue, 16 Sep 2025 22:04:50 +0200 Subject: [PATCH 2/2] use handling from PR191 - plot amplitude() no colorbar label as default - plot level() 'level / dB' as default - use extend = 'both' as already suggested by PR191 --- sfs/plot2d.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sfs/plot2d.py b/sfs/plot2d.py index abea658c..b28238c8 100644 --- a/sfs/plot2d.py +++ b/sfs/plot2d.py @@ -230,7 +230,7 @@ def _plotting_plane(p, grid): def amplitude(p, grid, *, xnorm=None, cmap='coolwarm_clip', vmin=-2.0, vmax=2.0, xlabel=None, ylabel=None, - colorbar=True, colorbar_kwargs={}, ax=None, **kwargs): + colorbar=True, colorbar_kwargs=None, ax=None, **kwargs): """Two-dimensional plot of sound field (real part). Parameters @@ -319,13 +319,14 @@ def amplitude(p, grid, *, xnorm=None, cmap='coolwarm_clip', ax.set_xlabel(xlabel) ax.set_ylabel(ylabel) if colorbar: - colorbar_kwargs.setdefault('label', 'relative pressure') + if colorbar_kwargs is None: + colorbar_kwargs = dict(extend='both') add_colorbar(im, **colorbar_kwargs) return im def level(p, grid, *, xnorm=None, power=False, cmap=None, vmax=3, vmin=-50, - **kwargs): + colorbar_kwargs=None, **kwargs): """Two-dimensional plot of level (dB) of sound field. Takes the same parameters as `sfs.plot2d.amplitude()`. @@ -340,9 +341,11 @@ def level(p, grid, *, xnorm=None, power=False, cmap=None, vmax=3, vmin=-50, if xnorm is not None: p = _util.normalize(p, grid, xnorm) L = _util.db(p, power=power) - kwargs.setdefault('colorbar_kwargs', {'label': 'level / dB'}) + if colorbar_kwargs is None: + colorbar_kwargs = dict(extend='both', label='level / dB') return amplitude(L, grid=grid, xnorm=None, cmap=cmap, - vmax=vmax, vmin=vmin, **kwargs) + vmax=vmax, vmin=vmin, + colorbar_kwargs=colorbar_kwargs, **kwargs) def level_contour(p, grid, *, xnorm=None, power=False,