Last active
May 17, 2021 13:59
-
-
Save GuillaumeFavelier/d8a08e19786e7291173951531f975c59 to your computer and use it in GitHub Desktop.
PyVista demo using MNE hemis - "mosaic" effect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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