Visualization¶
Visualization utilities for DDACS simulation data.
Overview¶
The visualization module provides flexible plotting functions that work with extracted data. This design allows you to see and understand your data before visualizing it.
Basic Workflow¶
from ddacs.utils import extract_mesh, extract_element_thickness
from ddacs.visualization import plot_mesh
# Step 1: Extract data (you see what you're working with)
vertices, faces = extract_mesh("simulation.h5", "blank", timestep=-1)
thickness = extract_element_thickness("simulation.h5", timestep=-1)
print(f"Mesh: {len(vertices)} vertices, {len(faces)} faces")
print(f"Thickness range: {thickness.min():.3f} - {thickness.max():.3f} mm")
# Step 2: Visualize
ax, cbar = plot_mesh(
vertices, faces,
values=thickness,
cmap="viridis",
vmin=0.8, vmax=1.15,
colorbar_label="Thickness [mm]"
)
Functions¶
plot_mesh(vertices, faces, values=None, ax=None, figsize=None, cmap='viridis', vmin=None, vmax=None, colorbar_label=None, title=None, axis_limits=None, **kwargs)
¶
Plot 3D mesh with optional per-face coloring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
ndarray
|
Vertex coordinates array of shape (n_vertices, 3). |
required |
faces
|
ndarray
|
Face indices array of shape (n_faces, 3). |
required |
values
|
ndarray | None
|
Optional per-face values for coloring (e.g., thickness, strain). If None, uses solid color. |
None
|
ax
|
Existing matplotlib 3D axis. If None, creates new figure. |
None
|
|
figsize
|
tuple[float, float] | None
|
Figure size as (width, height) in inches. |
None
|
cmap
|
str
|
Colormap name when values is provided. |
'viridis'
|
vmin
|
float | None
|
Minimum value for color scaling. If None, uses min(values). |
None
|
vmax
|
float | None
|
Maximum value for color scaling. If None, uses max(values). |
None
|
colorbar_label
|
str | None
|
Label for the colorbar (e.g., "Thickness [mm]"). |
None
|
title
|
str | None
|
Plot title. |
None
|
axis_limits
|
list[float] | None
|
Axis limits as [min, max]. Defaults to [0, 110]. |
None
|
**kwargs
|
Additional arguments passed to Poly3DCollection. Common options: color, edgecolor, linewidth, alpha, shade. |
{}
|
Returns:
| Type | Description |
|---|---|
|
If values is None: matplotlib axis object. |
|
|
If values is provided: Tuple of (axis, colorbar). |
Examples:
Solid color mesh: >>> vertices, faces = extract_mesh("sim.h5", "blank", timestep=2) >>> ax = plot_mesh(vertices, faces, color="blue")
Thickness distribution: >>> vertices, faces = extract_mesh("sim.h5", "blank", timestep=-1) >>> thickness = extract_element_thickness("sim.h5", timestep=-1) >>> ax, cbar = plot_mesh( ... vertices, faces, ... values=thickness, ... cmap="viridis", ... vmin=0.8, vmax=1.15, ... colorbar_label="Thickness [mm]" ... )
With custom edge styling: >>> ax = plot_mesh(vertices, faces, color="red", ... edgecolor="black", linewidth=0.5)
Source code in ddacs/visualization.py
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 | |
plot_point_cloud(coords, values=None, ax=None, figsize=None, cmap='plasma', vmin=None, vmax=None, colorbar_label=None, title=None, axis_limits=None, **kwargs)
¶
Plot 3D point cloud with optional per-point coloring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords
|
ndarray
|
Point coordinates array of shape (n_points, 3). |
required |
values
|
ndarray | None
|
Optional per-point values for coloring. If None, uses solid color. |
None
|
ax
|
Existing matplotlib 3D axis. If None, creates new figure. |
None
|
|
figsize
|
tuple[float, float] | None
|
Figure size as (width, height) in inches. |
None
|
cmap
|
str
|
Colormap name when values is provided. |
'plasma'
|
vmin
|
float | None
|
Minimum value for color scaling. |
None
|
vmax
|
float | None
|
Maximum value for color scaling. |
None
|
colorbar_label
|
str | None
|
Label for the colorbar. |
None
|
title
|
str | None
|
Plot title. |
None
|
axis_limits
|
list[float] | None
|
Axis limits as [min, max]. Defaults to [0, 110]. |
None
|
**kwargs
|
Additional arguments passed to ax.scatter. Common options: c (color), s (size), alpha, marker. |
{}
|
Returns:
| Type | Description |
|---|---|
|
If values is None: matplotlib axis object. |
|
|
If values is provided: Tuple of (axis, colorbar). |
Examples:
Simple point cloud: >>> coords = extract_point_cloud("sim.h5", "blank", timestep=2) >>> ax = plot_point_cloud(coords, c="blue", s=2)
Colored by springback: >>> coords, displacement = extract_point_springback("sim.h5") >>> magnitude = np.linalg.norm(displacement, axis=1) >>> ax, cbar = plot_point_cloud( ... coords, ... values=magnitude, ... colorbar_label="Springback [mm]" ... )
Source code in ddacs/visualization.py
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 | |
plot_vectors(coords, vectors, values=None, ax=None, figsize=None, step=25, scale=10.0, cmap='plasma', vmin=None, vmax=None, colorbar_label=None, title=None, axis_limits=None, show_points=True, point_kwargs=None, arrow_kwargs=None)
¶
Plot 3D vector field (quiver plot) for displacement visualization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords
|
ndarray
|
Point coordinates array of shape (n_points, 3). |
required |
vectors
|
ndarray
|
Vector components array of shape (n_points, 3). |
required |
values
|
ndarray | None
|
Optional per-point values for coloring the point cloud. If None, uses solid point color. |
None
|
ax
|
Existing matplotlib 3D axis. If None, creates new figure. |
None
|
|
figsize
|
tuple[float, float] | None
|
Figure size as (width, height) in inches. |
None
|
step
|
int
|
Subsampling step (every Nth point) for arrow density. |
25
|
scale
|
float
|
Scaling factor for arrow length. |
10.0
|
cmap
|
str
|
Colormap name when values is provided. |
'plasma'
|
vmin
|
float | None
|
Minimum value for color scaling. |
None
|
vmax
|
float | None
|
Maximum value for color scaling. |
None
|
colorbar_label
|
str | None
|
Label for the colorbar (if values is provided). |
None
|
title
|
str | None
|
Plot title. |
None
|
axis_limits
|
list[float] | None
|
Axis limits as [min, max]. Defaults to [0, 110]. |
None
|
show_points
|
bool
|
Whether to show point cloud beneath vectors. |
True
|
point_kwargs
|
dict | None
|
Additional arguments passed to ax.scatter for points. Common options: c (color), s (size), alpha. |
None
|
arrow_kwargs
|
dict | None
|
Additional arguments passed to ax.quiver for arrows. Common options: color, alpha, arrow_length_ratio. |
None
|
Returns:
| Type | Description |
|---|---|
|
If values is None: matplotlib axis object. |
|
|
If values is provided: Tuple of (axis, colorbar). |
Examples:
Simple vectors: >>> coords, displacement = extract_point_springback("sim.h5") >>> ax = plot_vectors(coords, displacement, step=50, scale=15)
With springback magnitude coloring: >>> coords, displacement = extract_point_springback("sim.h5") >>> magnitude = np.linalg.norm(displacement, axis=1) >>> ax, cbar = plot_vectors( ... coords, displacement, ... values=magnitude, ... colorbar_label="Springback [mm]", ... arrow_kwargs={"color": "darkred", "alpha": 0.8} ... )
Source code in ddacs/visualization.py
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 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
plot_2d_projection(coords, values=None, projection='xy', ax=None, figsize=None, cmap='plasma', vmin=None, vmax=None, colorbar_label=None, title=None, **kwargs)
¶
Plot 2D projection of point cloud (top view, side view, etc.).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords
|
ndarray
|
Point coordinates array of shape (n_points, 3). |
required |
values
|
ndarray | None
|
Optional per-point values for coloring. |
None
|
projection
|
str
|
Which 2D plane to project onto ("xy", "xz", "yz"). |
'xy'
|
ax
|
Existing matplotlib axis. If None, creates new figure. |
None
|
|
figsize
|
tuple[float, float] | None
|
Figure size as (width, height) in inches. |
None
|
cmap
|
str
|
Colormap name when values is provided. |
'plasma'
|
vmin
|
float | None
|
Minimum value for color scaling. |
None
|
vmax
|
float | None
|
Maximum value for color scaling. |
None
|
colorbar_label
|
str | None
|
Label for the colorbar. |
None
|
title
|
str | None
|
Plot title. |
None
|
**kwargs
|
Additional arguments passed to ax.scatter. Common options: c (color), s (size), alpha, marker. |
{}
|
Returns:
| Type | Description |
|---|---|
|
If values is None: matplotlib axis object. |
|
|
If values is provided: Tuple of (axis, colorbar). |
Example
coords, displacement = extract_point_springback("sim.h5") magnitude = np.linalg.norm(displacement, axis=1) ax, cbar = plot_2d_projection( ... coords, values=magnitude, ... projection="xy", ... colorbar_label="Springback [mm]", ... s=2, alpha=0.8 ... )
Source code in ddacs/visualization.py
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | |
Constants¶
COMPONENT_COLORS¶
Default colors for simulation components: