Note
Go to the end to download the full example code.
Generating a Random 3D Vector Field
In this example we are going to generate a random 3D vector field with a Gaussian covariance model. The mesh on which we generate the field will be externally defined and it will be generated by PyVista.
import pyvista as pv
import gstools as gs
# mainly for setting a white background
pv.set_plot_theme("document")
create a uniform grid with PyVista
create an incompressible random 3d velocity field on the given mesh with added mean velocity in x-direction
Now, we can do the plotting
streamlines = mesh.streamlines(
"Velocity",
terminal_speed=0.0,
n_points=800,
source_radius=2.5,
)
# set a fancy camera position
cpos = [(25, 23, 17), (0, 10, 0), (0, 0, 1)]
p = pv.Plotter()
# adding an outline might help navigating in 3D space
# p.add_mesh(mesh.outline(), color="k")
p.add_mesh(
streamlines.tube(radius=0.005),
show_scalar_bar=False,
diffuse=0.5,
ambient=0.5,
)
Note
PyVista is not working on readthedocs, but you can try it out yourself by uncommenting the following line of code.
# p.show(cpos=cpos)
The result should look like this:
Total running time of the script: (0 minutes 17.776 seconds)