Visualization¶
The voids.visualization sub-package provides network rendering via Plotly and
PyVista.
PyVista dependency
PyVista is installed as a core dependency of voids and is available by
default when you install the package.
Plotly¶
voids.visualization.plotly
¶
plot_network_plotly
¶
plot_network_plotly(
net,
*,
point_scalars=None,
cell_scalars=None,
point_sizes=None,
throat_sizes=None,
point_size=None,
line_width=None,
line_opacity=0.4,
size_scale=1.0,
point_size_limits=None,
throat_size_limits=None,
max_throats=1000,
title=None,
show_colorbar=True,
layout_kwargs=None,
)
Create an interactive Plotly visualization of a pore-throat network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
net
|
Network
|
Network to render. |
required |
point_scalars
|
str | ndarray | None
|
Pore field name or explicit pore-valued array with shape |
None
|
cell_scalars
|
str | ndarray | None
|
Throat field name or explicit throat-valued array with shape |
None
|
point_sizes
|
str | ndarray | bool | None
|
Pore/throat characteristic size field name, explicit size array, |
None
|
throat_sizes
|
str | ndarray | bool | None
|
Pore/throat characteristic size field name, explicit size array, |
None
|
point_size
|
float | None
|
Constant marker size for pores when explicit size rendering is disabled. When size-driven rendering is active, this acts as the reference marker size for median-sized pores. |
None
|
line_width
|
float | None
|
Constant line width for throats when explicit size rendering is disabled. When size-driven rendering is active, this acts as the reference width for median-sized throats. |
None
|
line_opacity
|
float
|
Opacity applied to throat lines. |
0.4
|
size_scale
|
float
|
Multiplicative factor applied to size-driven pore markers and throat widths. |
1.0
|
point_size_limits
|
tuple[float | None, float | None] | None
|
Optional |
None
|
throat_size_limits
|
tuple[float | None, float | None] | None
|
Optional |
None
|
max_throats
|
int | None
|
Maximum number of throats to draw. Large networks are downsampled for responsiveness. |
1000
|
title
|
str | None
|
Figure title. |
None
|
show_colorbar
|
bool
|
If |
True
|
layout_kwargs
|
dict[str, Any] | None
|
Optional Plotly layout overrides. |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
Interactive 3D figure. |
Notes
If only pore scalars are given, each throat is colored by the arithmetic mean of its endpoint pore values:
s_throat = 0.5 * (s_i + s_j)
The throat colormap is normalized with the same scalar bounds as the pore markers so that equal numerical values map to equal colors across pores and throats.
Source code in src/voids/visualization/plotly.py
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 | |
PyVista¶
voids.visualization.pyvista
¶
network_to_pyvista_polydata
¶
network_to_pyvista_polydata(
net,
*,
point_scalars=None,
cell_scalars=None,
include_all_numeric_fields=False,
)
Convert a network to pyvista.PolyData.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
net
|
Network
|
Network to convert. |
required |
point_scalars
|
str | ndarray | None
|
Pore/throat scalar field name or explicit array. |
None
|
cell_scalars
|
str | ndarray | None
|
Pore/throat scalar field name or explicit array. |
None
|
include_all_numeric_fields
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
PolyData
|
PolyData with pores as points and throats as line cells. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If a requested scalar field name is missing. |
ValueError
|
If an explicit scalar array has the wrong shape. |
Source code in src/voids/visualization/pyvista.py
plot_network_pyvista
¶
plot_network_pyvista(
net,
*,
point_scalars=None,
cell_scalars=None,
point_sizes=None,
throat_sizes=None,
show_points=True,
show_lines=True,
line_width=None,
point_size=None,
render_tubes=False,
tube_radius=None,
size_scale=1.0,
off_screen=False,
screenshot=None,
show_axes=True,
notebook=None,
**add_mesh_kwargs,
)
Render a pore network with PyVista.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
net
|
Network
|
Network to render. |
required |
point_scalars
|
str | ndarray | None
|
Pore/throat scalar field name or explicit array. |
None
|
cell_scalars
|
str | ndarray | None
|
Pore/throat scalar field name or explicit array. |
None
|
point_sizes
|
str | ndarray | bool | None
|
Pore/throat characteristic size field name, explicit size array, |
None
|
throat_sizes
|
str | ndarray | bool | None
|
Pore/throat characteristic size field name, explicit size array, |
None
|
show_points
|
bool
|
Toggle pore and throat rendering. |
True
|
show_lines
|
bool
|
Toggle pore and throat rendering. |
True
|
line_width
|
float | None
|
Width used for line rendering when throat sizes are not rendered with tubes. |
None
|
point_size
|
float | None
|
Marker size used for pores when size-driven sphere rendering is disabled. |
None
|
render_tubes
|
bool
|
If |
False
|
tube_radius
|
float | None
|
Optional tube radius when |
None
|
size_scale
|
float
|
Multiplicative factor applied to point diameters and throat radii in world units. |
1.0
|
off_screen
|
bool
|
If |
False
|
screenshot
|
str | None
|
Optional screenshot output path. When provided, the plot is rendered and saved. |
None
|
show_axes
|
bool
|
If |
True
|
notebook
|
bool | None
|
Optional PyVista notebook flag. Defaults to |
None
|
**add_mesh_kwargs
|
Any
|
Additional keyword arguments forwarded to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
tuple
|
Pair |
Notes
For throat rendering, scalar selection follows this priority:
- explicit throat/cell scalar data
- pore/point scalar data, reused on the line representation
This allows pore-defined pressure fields to color both pores and throats in a consistent network visualization.
When tube rendering is requested (via render_tubes, tube_radius, or
automatically detected variable throat sizes) but the PyVista tube filter is
unavailable or raises an exception, rendering falls back to line geometry with
render_lines_as_tubes=True so that a tube-like appearance is preserved.
Variable throat radii cannot be accurately represented in this fallback mode;
a :class:UserWarning is emitted to notify callers.
Source code in src/voids/visualization/pyvista.py
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 | |