Skip to content

Instantly share code, notes, and snippets.

@dennissergeev
Created August 9, 2019 13:21
Show Gist options
  • Save dennissergeev/54b7908049df31ad1d0b8954883fe3f2 to your computer and use it in GitHub Desktop.
Save dennissergeev/54b7908049df31ad1d0b8954883fe3f2 to your computer and use it in GitHub Desktop.
import pyvista as pv
import numpy as np
arr = np.random.rand(40, 72, 144)
grid = pv.UniformGrid()
grid.dimensions = np.array(arr.shape) + 1
grid.origin = (0, 0, 0) # The bottom left corner of the data set
grid.spacing = (1, 1, 1) # These are the cell sizes along each axis
grid.cell_arrays["values"] = arr.flatten(order="F") # Flatten the array!
nodal = grid.cell_data_to_point_data()
# geom = nodal.extract_geometry()
contours = nodal.contour(isosurfaces=[0.2, 0.4, 0.9])
contours.plot(cmap='Spectral')
plotter = pv.Plotter() # instantiate the plotter
plotter.add_mesh(contours) # add a dataset to the scene
plotter.show() # show the rendering window
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment