Plotting Module#
The Plotting module provides functions for generating visualizations of bank lines, erosion results, and other data in the D-FAST Bank Erosion software.
Overview#
The Plotting module contains functions for creating various types of plots and visualizations that help users understand the results of bank line detection and erosion calculations. These visualizations include maps of bank lines, erosion profiles, and time series of erosion volumes.
Components#
The Plotting module consists of the following components:
Plotting Functions#
dfastbe.plotting
#
Copyright (C) 2020 Stichting Deltares.
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, see http://www.gnu.org/licenses/.
contact: delft3d.support@deltares.nl Stichting Deltares P.O. Box 177 2600 MH Delft, The Netherlands
All indications and logos of, and references to, "Delft3D" and "Deltares" are registered trademarks of Stichting Deltares, and remain the property of Stichting Deltares. All rights reserved.
INFORMATION This file is part of D-FAST Bank Erosion: https://github.com/Deltares/D-FAST_Bank_Erosion
BasePlot
#
Source code in src/dfastbe/plotting.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 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 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
|
get_colors(cmap_name: str, n: int) -> List[Tuple[float, float, float]]
#
Obtain N colors from the specified colormap.
Arguments#
cmap_name : str Name of the color map. n : int Number of colors to be returned.
Returns#
clrcyc : List[Tuple[float, float, float]] List of colour tuplets.
Source code in src/dfastbe/plotting.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
|
plot_mesh(ax: Axes, xe: np.ndarray, ye: np.ndarray, scale: float = 1000) -> None
#
Add a mesh to a plot.
Arguments#
ax : matplotlib.axes.Axes Axes object in which to add the mesh. xe : np.ndarray M x 2 array of begin/end x-coordinates of mesh edges. ye : np.ndarray M x 2 array of begin/end y-coordinates of mesh edges. scale : float Indicates whether the axes are in m (1) or km (1000).
Source code in src/dfastbe/plotting.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
plot_mesh_patches(ax: Axes, simulation_data: BaseSimulationData, minval: Optional[float] = None, maxval: Optional[float] = None, scale: float = 1000) -> matplotlib.collections.PolyCollection
#
Add a collection of patches to the plot one for every face of the mesh.
Arguments#
ax : matplotlib.axes.Axes Axes object in which to add the mesh. minval : Optional[float] Lower limit for the color scale. maxval : Optional[float] Upper limit for the color scale. scale : float Indicates whether the axes are in m (1) or km (1000).
Returns#
p : matplotlib.collections.PolyCollection Patches object.
Source code in src/dfastbe/plotting.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
save_fig(fig: Figure, filename: Union[str, Path]) -> None
#
Save a single figure to file.
Arguments#
fig : matplotlib.figure.Figure Figure to be saved. filename : str Name of the file to be written.
Source code in src/dfastbe/plotting.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
save_plot(fig: Figure, ax: Axes, figure_index: int, plot_name: str, zoom_coords: Optional[List[Tuple[float, float, float, float]]], plot_flags: Dict[str, Any], zoom_xy: bool) -> int
#
Save the plot to a file.
Source code in src/dfastbe/plotting.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
|
set_axes_properties(ax: Axes, chainage_txt: str, ylabel_txt: str, grid: bool, title_txt: str, handles: Optional[List[Any]] = None, labels: Optional[List[str]] = None) -> None
#
Set the properties of the axes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ax
|
Axes
|
The axes object to set properties for. |
required |
chainage_txt
|
str
|
Label for the horizontal chainage axes. |
required |
ylabel_txt
|
str
|
Label for the vertical axes. |
required |
title_txt
|
str
|
Title for the plot. |
required |
Source code in src/dfastbe/plotting.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
|
set_bbox(ax: Axes, bbox: Tuple[float, float, float, float], scale: float = 1000) -> None
#
Specify the bounding limits of an axes object.
Arguments#
ax : matplotlib.axes.Axes Axes object to be adjusted. bbox : Tuple[float, float, float, float] Tuple containing boundary limits (xmin, ymin, xmax, ymax); unit m. scale: float Indicates whether the axes are in m (1) or km (1000).
Source code in src/dfastbe/plotting.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
set_size(fig: Figure) -> None
#
Set the size of a figure.
Currently, the size is hardcoded, but functionality may be extended in the future.
Arguments#
fig : matplotlib.figure.Figure Figure to be saved.
Source code in src/dfastbe/plotting.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
stations_marker(xykm: np.ndarray, ax: Axes, float_format: int = 1, scale: float = 1000) -> None
#
Add markers indicating the river chainage to a plot.
Arguments#
xykm : np.ndarray Array containing the x, y, and chainage; unit m for x and y, km for chainage. ax : matplotlib.axes.Axes Axes object in which to add the markers. float_format : int Number of decimals used for marks. scale: float Indicates whether the axes are in m (1) or km (1000).
Source code in src/dfastbe/plotting.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
zoom_x_and_save(fig: Figure, ax: Axes, figbase: Path, plot_ext: str, xzoom: List[Tuple[float, float]]) -> None
#
Zoom in on subregions of the x-axis and save the figure.
Arguments#
fig : matplotlib.figure.Figure Figure to be processed. ax : matplotlib.axes.Axes Axes to be processed. fig_base : str Base name of the figure to be saved. plot_ext : str File extension of the figure to be saved. xzoom : List[list[float,float]] Values at which to split the x-axis.
Source code in src/dfastbe/plotting.py
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 |
|
zoom_xy_and_save(fig: Figure, ax: Axes, fig_base: Path, plot_ext: str, xyzoom: List[Tuple[float, float, float, float]], scale: float = 1000) -> None
#
Zoom in on subregions in x,y-space and save the figure.
Arguments#
fig : matplotlib.figure.Figure Figure to be processed. ax : matplotlib.axes.Axes Axes to be processed. fig_base : str Base name of the figure to be saved. plot_ext : str File extension of the figure to be saved. xyzoom : List[List[float, float, float, float]] List of xmin, xmax, ymin, ymax values to zoom into. scale: float Indicates whether the axes are in m (1) or km (1000).
Source code in src/dfastbe/plotting.py
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 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
|
The plotting functions component provides functions for creating various types of visualizations, such as:
- Maps of bank lines and erosion results
- Profiles of bank erosion
- Time series of erosion volumes
- Visualizations of hydrodynamic data
Workflow#
The typical workflow for using the Plotting module is:
- Perform bank line detection or erosion calculation
- Call the appropriate plotting functions to visualize the results
- Display the plots or save them to files
Usage Example#
import matplotlib.pyplot as plt
from dfastbe import plotting as df_plt
from dfastbe.io.config import ConfigFile
from dfastbe.bank_erosion.bank_erosion import Erosion
# Load configuration file
config_file = ConfigFile.read("config.cfg")
# Initialize Erosion object
erosion = Erosion(config_file)
# Run erosion calculation
erosion.run()
# Create a plot of the results
fig, ax = plt.subplots(figsize=(10, 8))
df_plt.plot_bank_lines(ax, bank_lines, color='blue', linewidth=1.5)
df_plt.plot_erosion_results(ax, erosion_results, cmap='viridis')
plt.savefig("erosion_results.png")
plt.show()
For more details on the specific functions, refer to the API reference below.