Skip to content

Instantly share code, notes, and snippets.

@GuillaumeFavelier
Last active May 17, 2021 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GuillaumeFavelier/d8a08e19786e7291173951531f975c59 to your computer and use it in GitHub Desktop.
Save GuillaumeFavelier/d8a08e19786e7291173951531f975c59 to your computer and use it in GitHub Desktop.
PyVista demo using MNE hemis - "mosaic" effect
import pyvista as pv
import numpy as np
from matplotlib.colors import ListedColormap
plotter = pv.Plotter(
point_smoothing=True,
line_smoothing=True,
polygon_smoothing=True,
)
plotter.enable_anti_aliasing()
plotter.set_background('white')
# from: https://coolors.co/palettes/trending
cmap = [
(38, 70, 83),
(42, 157, 143),
(233, 196, 106),
(244, 162, 97),
(231, 111, 81),
]
ctable = np.round(cmap).astype(np.uint8)
ctable = ListedColormap(ctable / 255.)
for hemi in ('lh', 'rh'):
# from: https://github.com/mne-tools/mne-python
surface = pv.read(f"brain_{hemi}.vtk").decimate(0.9)
if hemi == 'lh':
surface.translate((-100, 0, 0))
ncells = surface.number_of_cells
surface.cell_arrays["data"] = np.random.randint(0, len(cmap), ncells)
plotter.add_mesh(
mesh=surface,
specular=1.0,
smooth_shading=False,
show_scalar_bar=False,
scalars="data",
cmap=ctable,
silhouette=dict(color="black", line_width=4),
)
plotter.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment