.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/simple_surface_rendering/plot_all_surfaces.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_simple_surface_rendering_plot_all_surfaces.py: ================ Cortex, subcortex, cerebellum, and brainstem surface rendering ================ This is a quick demo for how to plot a surface mesh rendering for the cortex, subcortex, cerebellum, and brainstem. Here, we use the template GIFTI data, but you can also use your own GIFTI data. You can plot just the cortex (first image below), just the cortex and subcortex (second image below), or the cortex, subcortex, cerebellum, and brainstem (third image below). .. GENERATED FROM PYTHON SOURCE LINES 12-16 .. code-block:: default import matplotlib.pyplot as plt from cerebro import cerebro_brain_utils as cbu from cerebro import cerebro_brain_viewer as cbv .. GENERATED FROM PYTHON SOURCE LINES 17-19 Plotting cortex surface only ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. GENERATED FROM PYTHON SOURCE LINES 19-37 .. code-block:: default # Define a viewer cortex_viewer = cbv.Cerebro_brain_viewer(offscreen=True,background_color=(255,255,255,1)) surface_model = cortex_viewer.load_template_GIFTI_cortical_surface_models(template_surface="pial") cifti_space = cortex_viewer.visualize_cifti_space( volumetric_structures="none" # Change to "none" for just cortex, or "subcortex" for just cortex and subcortex ) fig, ax = plt.subplots(figsize=(8,7)) plt.subplots_adjust(wspace=0, hspace=0) ax.axis('off') cortex_viewer.offscreen_draw_to_matplotlib_axes(ax) # Clear this viewer cortex_viewer.viewer.window.destroy() plt.show() .. image-sg:: /auto_examples/simple_surface_rendering/images/sphx_glr_plot_all_surfaces_001.png :alt: plot all surfaces :srcset: /auto_examples/simple_surface_rendering/images/sphx_glr_plot_all_surfaces_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 38-41 Cortex and subcortex ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ You also have the option to plot the cortex and subcortex together. .. GENERATED FROM PYTHON SOURCE LINES 41-59 .. code-block:: default # Define a viewer cortex_subcortex_viewer = cbv.Cerebro_brain_viewer(offscreen=True,background_color=(255,255,255,1)) surface_model = cortex_subcortex_viewer.load_template_GIFTI_cortical_surface_models(template_surface="pial") cifti_space = cortex_subcortex_viewer.visualize_cifti_space( volumetric_structures="subcortex" # Change to "none" for just cortex, or "all" for cortex, subcortex, cerebellum, and brainstem ) fig, ax = plt.subplots(figsize=(8,7)) plt.subplots_adjust(wspace=0, hspace=0) ax.axis('off') cortex_subcortex_viewer.offscreen_draw_to_matplotlib_axes(ax) # Clear this viewer cortex_subcortex_viewer.viewer.window.destroy() plt.show() .. image-sg:: /auto_examples/simple_surface_rendering/images/sphx_glr_plot_all_surfaces_002.png :alt: plot all surfaces :srcset: /auto_examples/simple_surface_rendering/images/sphx_glr_plot_all_surfaces_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 60-63 Cortex, subcortex, brainstem, and cerebellum ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Lastly, you can show all of the brain structures together -- cortex, subcortex, brainstem, and cerebellum. .. GENERATED FROM PYTHON SOURCE LINES 63-81 .. code-block:: default # Define a viewer all_viewer = cbv.Cerebro_brain_viewer(offscreen=True,background_color=(255,255,255,1)) surface_model = all_viewer.load_template_GIFTI_cortical_surface_models(template_surface="pial") cifti_space = all_viewer.visualize_cifti_space( volumetric_structures="all" # Change to "none" for just cortex, or "subcortex" for just cortex and subcortex ) fig, ax = plt.subplots(figsize=(8,7)) plt.subplots_adjust(wspace=0, hspace=0) ax.axis('off') all_viewer.offscreen_draw_to_matplotlib_axes(ax) # Clear this viewer all_viewer.viewer.window.destroy() plt.show() .. image-sg:: /auto_examples/simple_surface_rendering/images/sphx_glr_plot_all_surfaces_003.png :alt: plot all surfaces :srcset: /auto_examples/simple_surface_rendering/images/sphx_glr_plot_all_surfaces_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 82-85 Using your own surface data ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ If you have your own surface data in GIFTI format, here's how you can plot it -- with this example showing a cortical flatmap: .. GENERATED FROM PYTHON SOURCE LINES 85-115 .. code-block:: default # Define a viewer your_surface_viewer = cbv.Cerebro_brain_viewer(offscreen=True,background_color=(255,255,255,1)) # Define your left and right surface GIFTI files from pathlib import Path try: main_path = Path(__file__).parents[3] except NameError: import sys main_path = Path(sys.argv[0]).parents[3] left_surface_file = f"{main_path}/code/data/templates/HCP/surfaces/S1200.L.inflated_MSMAll.32k_fs_LR.surf.gii" right_surface_file = f"{main_path}/code/data/templates/HCP/surfaces/S1200.R.inflated_MSMAll.32k_fs_LR.surf.gii" surface_model = your_surface_viewer.load_GIFTI_cortical_surface_models( left_surface_file=left_surface_file, right_surface_file=right_surface_file ) cifti_space = your_surface_viewer.visualize_cifti_space( volumetric_structures="subcortex" ) fig, ax = plt.subplots(figsize=(8,7)) plt.subplots_adjust(wspace=0, hspace=0) ax.axis('off') your_surface_viewer.offscreen_draw_to_matplotlib_axes(ax) # Clear this viewer your_surface_viewer.viewer.window.destroy() plt.show() .. image-sg:: /auto_examples/simple_surface_rendering/images/sphx_glr_plot_all_surfaces_004.png :alt: plot all surfaces :srcset: /auto_examples/simple_surface_rendering/images/sphx_glr_plot_all_surfaces_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 12.873 seconds) .. _sphx_glr_download_auto_examples_simple_surface_rendering_plot_all_surfaces.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_all_surfaces.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_all_surfaces.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_