Create Connected Lines from Points#

Build a polyline from ordered points with pyvista.MultipleLines().

import numpy as np
import pyvista as pv

Create a winding polyline#

The points are connected in the order they are given.

t = np.linspace(0, 1, 100)
points = np.column_stack(
    (
        6 * t - 3,
        np.sin(2 * np.pi * t),
        0.5 * np.cos(3 * np.pi * t),
    ),
)

line = pv.MultipleLines(points)
line['height'] = points[:, 1]
line
PolyData (0x7bf18c7bb8e0)
  N Cells:    1
  N Points:   100
  N Strips:   0
  X Bounds:   -3.000e+00, 3.000e+00
  Y Bounds:   -9.999e-01, 9.999e-01
  Z Bounds:   -5.000e-01, 5.000e-01
  N Arrays:   2


Plot the line as a tube#

Tubing the polyline gives it visible thickness in 3D.

pl = pv.Plotter()
pl.add_mesh(line.tube(radius=0.08), scalars='height', cmap='viridis')
pl.show()
create multiple lines

Tags: load

Total running time of the script: (0 minutes 1.315 seconds)

Gallery generated by Sphinx-Gallery