Bathymetry Plotting¶
sensingpy.bathymetry.plot provides specialised plotting classes and helper
functions for visualising bathymetry calibration and validation results.
CalibrationPlot¶
CalibrationPlot
¶
CalibrationPlot(title_font_size: int = 30, label_font_size: int = 20, tick_font_size: int = 15, legend_font_size: int = 20, font_family: str = 'Times New Roman')
Bases: object
Class for creating standardized bathymetry calibration plots.
This class provides methods for plotting calibration data for satellite-derived bathymetry models, including regression lines, scatterplots, and statistics. It handles consistent styling and formatting across plots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title_font_size
|
int
|
Font size for plot titles, by default 30 |
30
|
label_font_size
|
int
|
Font size for axis labels, by default 20 |
20
|
tick_font_size
|
int
|
Font size for axis ticks, by default 15 |
15
|
legend_font_size
|
int
|
Font size for legend text, by default 20 |
20
|
font_family
|
str
|
Font family for all text elements, by default 'Times New Roman' |
'Times New Roman'
|
Constructor with the size of the texts
Source code in sensingpy/bathymetry/plot.py
Attributes¶
Functions¶
add_calibration_scatter
¶
add_calibration_scatter(model: LinearModel, x: ndarray, y: ndarray, ax: Axes, c: str = 'g', **kwargs) -> Axes
Plot regression data with model fit line and statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
LinearModel
|
Calibrated linear model with slope, intercept and R² values |
required |
x
|
ndarray
|
x-axis values (predictor variables) |
required |
y
|
ndarray
|
y-axis values (observed depths) |
required |
ax
|
Axes
|
Matplotlib axes on which to plot |
required |
c
|
str
|
Color for scatter points, by default 'g' |
'g'
|
**kwargs
|
Additional keyword arguments passed to scatter() |
{}
|
Returns:
| Type | Description |
|---|---|
Axes
|
Matplotlib axes with plotted data |
Notes
The plot includes the best-fit line, R² value, linear equation, and sample size in the legend.
Source code in sensingpy/bathymetry/plot.py
add_legend
¶
Add formatted legend to axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Matplotlib axes to which legend will be added |
required |
Returns:
| Type | Description |
|---|---|
Axes
|
Matplotlib axes with legend |
Notes
The legend is formatted according to the font settings specified during class initialization, with handles hidden.
Source code in sensingpy/bathymetry/plot.py
add_labels
¶
Add formatted title and axis labels to plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Matplotlib axes to which labels will be added |
required |
title
|
str
|
Plot title, by default None |
None
|
xlabel
|
str
|
x-axis label, by default None |
None
|
ylabel
|
str
|
y-axis label, by default None |
None
|
Returns:
| Type | Description |
|---|---|
Axes
|
Matplotlib axes with labels |
Notes
Labels are formatted according to the font settings specified during class initialization.
Source code in sensingpy/bathymetry/plot.py
ValidationPlot¶
ValidationPlot
¶
ValidationPlot(title_font_size: int = 30, label_font_size: int = 20, tick_font_size: int = 15, legend_font_size: int = 20, font_family: str = 'Times New Roman')
Bases: object
Class for creating standardized bathymetry validation plots.
This class provides methods for visualizing and evaluating the performance of satellite-derived bathymetry models, including density scatter plots and error histograms with statistical metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title_font_size
|
int
|
Font size for plot titles, by default 30 |
30
|
label_font_size
|
int
|
Font size for axis labels, by default 20 |
20
|
tick_font_size
|
int
|
Font size for axis ticks, by default 15 |
15
|
legend_font_size
|
int
|
Font size for legend text, by default 20 |
20
|
font_family
|
str
|
Font family for all text elements, by default 'Times New Roman' |
'Times New Roman'
|
Constructor with the size of the texts
Source code in sensingpy/bathymetry/plot.py
Attributes¶
Functions¶
add_densed_scatter
¶
add_densed_scatter(summary: ValidationSummary, ax: Axes, s: float = 5, cmap: str = 'viridis_r', vmin: float = None, vmax: float = None, x_min: int = None, x_max: int = None, step=2, density: Mapping[str, Any] = None) -> Tuple[Axes, Any]
Create a density-colored scatter plot comparing modeled vs. in-situ depths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
summary
|
ValidationSummary
|
Validation summary object containing model predictions and ground truth |
required |
ax
|
Axes
|
Matplotlib axes on which to plot |
required |
s
|
float
|
Point size for scatter plot, by default 5 |
5
|
cmap
|
str
|
Matplotlib colormap for density representation, by default 'viridis_r' |
'viridis_r'
|
vmin
|
float
|
Minimum value for colormap normalization, by default None |
None
|
vmax
|
float
|
Maximum value for colormap normalization, by default None |
None
|
density
|
Mapping[str, Any]
|
Settings for density calculation, by default None. Format: {'method': 'precise'|'approximate', 'bins': int} |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[Axes, Any]
|
Matplotlib axes with plot and the colorbar mappable object |
Notes
Point color represents data density, helping visualize the distribution of points in crowded scatter plots. A 1:1 line is added to show perfect agreement between model and observations.
Source code in sensingpy/bathymetry/plot.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
add_residuals
¶
add_residuals(summary: ValidationSummary, ax: Axes, x_lim: int = 5, metrics: List[str] = None, **hist_kwargs) -> Axes
Create a histogram of model residuals with statistical metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
summary
|
ValidationSummary
|
Validation summary object containing error statistics |
required |
ax
|
Axes
|
Matplotlib axes on which to plot |
required |
x_lim
|
int
|
Symmetric x-axis limit for histogram, by default 5 |
5
|
metrics
|
List[str]
|
List of metric names to display in legend, by default None |
None
|
**hist_kwargs
|
Additional keyword arguments passed to seaborn's histplot() |
{}
|
Returns:
| Type | Description |
|---|---|
Axes
|
Matplotlib axes with plotted histogram |
Notes
The histogram shows the distribution of residual errors (in-situ minus model predictions), with a kernel density estimate overlay. Statistical metrics are shown in a text box on the plot.
Source code in sensingpy/bathymetry/plot.py
add_labels
¶
Add formatted title and axis labels to plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Matplotlib axes to which labels will be added |
required |
title
|
str
|
Plot title, by default None |
None
|
xlabel
|
str
|
x-axis label, by default None |
None
|
ylabel
|
str
|
y-axis label, by default None |
None
|
Returns:
| Type | Description |
|---|---|
Axes
|
Matplotlib axes with labels |
Notes
Labels are formatted according to the font settings specified during class initialization.
Source code in sensingpy/bathymetry/plot.py
get_precise_density¶
get_precise_density
¶
Calculate accurate point density using Gaussian kernel density estimation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
x-coordinates (in-situ depth values) |
required |
y
|
ndarray
|
y-coordinates (modeled depth values) |
required |
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, ndarray, ndarray, Any]
|
x-values, y-values, density values, and colormap normalization |
Notes
This method uses scipy's gaussian_kde for accurate kernel density estimation. It provides smooth density estimates but can be computationally intensive for large datasets.
Source code in sensingpy/bathymetry/plot.py
get_approximate_density¶
get_approximate_density
¶
get_approximate_density(X: ndarray, y: ndarray, bins: int) -> Tuple[np.ndarray, np.ndarray, np.ndarray, Any]
Calculate approximate point density using 2D histogram and interpolation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
x-coordinates (in-situ depth values) |
required |
y
|
ndarray
|
y-coordinates (modeled depth values) |
required |
bins
|
int
|
Number of bins for the 2D histogram |
required |
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, ndarray, ndarray, Any]
|
x-values, y-values, density values, and colormap normalization |
Notes
This method uses numpy's histogram2d and scipy's interpn for faster but less accurate density estimation. It's more suitable for large datasets where performance is a concern.