top of page

Create 3D plot

  • Peter Mortier
  • Mar 13
  • 1 min read

Updated: 6 days ago

In this example, we will illustrate how you can easily create a 3D plot with only a few lines of code. First, we create a regular grid consisting of triangular elements. The Z coordinates of the vertices are modified based on the X and Y coordinates to create a 3D plot.


Please note that the translate uses 10.01, and not 10.0. This is to avoid there is a point at the origin, as this would result in a division by zero.


from hellotriangle import shapes
import numpy as np

# create rectangular grid in XY plane consisting of triangles
unit = shapes.quad(eltype='tri3')

# refine and scale 
grid = unit.subdivide(100).scale(20.0)

# center the grid
grid = grid.translate([-10.01, -10.01, 0.0])

# add sinus wave to Z coordinates
X = grid.coords.x
Y = grid.coords.y

R = np.sqrt(X**2 + Y**2)
grid.coords.z = (np.sin(R) / R) * 7.0

# draw
draw(grid, color = "#D62246")

Create 3D plot
Figure: 3D plot created through the above script

Subscribe to our newsletter

Join our email list and get updates about HelloTriangle. Unsubscribe anytime.

Thanks for submitting!

© 2024 by HelloTriangle

  • LinkedIn
bottom of page