Visualisation of the 3d scalar field
import numpy as np
from vedo import Points, Sphere, Glyph, show
#
# ---------------------------------------------------------
# Load scalar field: expected columns = x y z value
# ---------------------------------------------------------
data = np.loadtxt("./scalar_field.txt")
x, y, z, s = data.T
#
# Create numpy array of 3D points
pts = np.vstack((x, y, z)).T
#
# Create vedo Points object
cloud = Points(pts)
cloud.pointdata["scalar"] = s # attach scalar field
#
# Create sphere glyphs (one per point)
sphere = Sphere(r=0.02) # base glyph geometry
#
# Glyph works with: Glyph(input_points, glyph_object)
glyphs = Glyph(cloud, sphere)
#
# Color glyphs by scalar values
glyphs.cmap("viridis", cloud.pointdata["scalar"])
glyphs.add_scalarbar(title="Scalar Value")
#
# Render
show(
glyphs,
axes=1,
bg="midnightblue",
title="Scalar Field Visualization (pyvedo)"
)
Visualisation of the 3d vector field
import numpy as np
from vedo import Points, Arrow, Glyph, show
#
# -------------------------------
# Load vector field: x y z vx vy vz
# -------------------------------
data = np.loadtxt("./vector_field.txt")
x, y, z, vx, vy, vz = data.T
#
pts = np.column_stack((x, y, z))
vectors = np.column_stack((vx, vy, vz))
magnitudes = np.linalg.norm(vectors, axis=1)
#
# -------------------------------
# Create Points object
# -------------------------------
cloud = Points(pts)
cloud.pointdata["vectors"] = vectors
cloud.pointdata["magnitude"] = magnitudes
#
# -------------------------------
# Create base arrow
# -------------------------------
arrow = Arrow([0, 0, 0], [1, 0, 0], s=0.01)
arrow.scale(0.1)
#
# -------------------------------
# Create glyphs (old style)
# -------------------------------
glyphs = Glyph(cloud, arrow)
glyphs.cmap("viridis", magnitudes)
glyphs.add_scalarbar(title="Vector Magnitude")
glyphs.pointdata["magnitude"] = np.repeat(magnitudes, arrow.npoints)
#
# -------------------------------
# Render
show(glyphs, axes=1, bg="midnightblue",
title="Vector Field Visualization")