.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/surface_analyses/plot_geodesic_path.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_surface_analyses_plot_geodesic_path.py: ======================= Plotting Geodesic Paths ======================= This will plot a geodesic path between two vertices on the cortical surface. This path is based on geodesic distances across the surface. The path starts at the given endpoint and selects the neighbor of that point in the surface map that is closest to the other endpoint. This process continues iteratilvely until the last vertex in the path is the endpoint you gave to it. All you need to do is supply a surface object and two vertices on that surface and you can find the geodesic path. This script additionally makes a plot to show all of the vertices listed in the path. .. GENERATED FROM PYTHON SOURCE LINES 16-47 .. image-sg:: /auto_examples/surface_analyses/images/sphx_glr_plot_geodesic_path_001.png :alt: plot geodesic path :srcset: /auto_examples/surface_analyses/images/sphx_glr_plot_geodesic_path_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none ** (inkscape:5087): WARNING **: 21:56:12.345: Failed to wrap object of type 'GtkRecentManager'. Hint: this error is commonly caused by failing to call a library init() function. | .. code-block:: Python import cortex import cortex.polyutils import numpy as np import matplotlib.pyplot as plt subject = "S1" # First we need to import the surfaces for this subject surfs = [cortex.polyutils.Surface(*d) for d in cortex.db.get_surf(subject, "fiducial")] numl = surfs[0].pts.shape[0] numr = surfs[1].pts.shape[0] num_vertices = numl + numr # Now we need to pick the start and end points of the line we will draw pt_a = 100 pt_b = 50000 # Then we find the geodesic path between these points path = surfs[0].geodesic_path(pt_a, pt_b) # In order to plot this on the cortical surface, we need an array that is the # same size as the number of vertices path_data = np.zeros(num_vertices) * np.nan for v in path: path_data[v] = 1 # And now plot these distances onto the cortical surface path_verts = cortex.Vertex(path_data, subject, cmap="Reds", vmin=0, vmax=1) cortex.quickshow(path_verts, with_colorbar=False, with_curvature=True) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 6.687 seconds) .. _sphx_glr_download_auto_examples_surface_analyses_plot_geodesic_path.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_geodesic_path.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_geodesic_path.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_geodesic_path.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_