.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/quickflat/plot_zoom_to_roi.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_quickflat_plot_zoom_to_roi.py: ================================= Plotting a zoomed view of one ROI ================================= Sometimes it is useful to create a flatmap that is zoomed in one just a single ROI. The location of the ROI can be inferred automatically, making it easy to show just the region around that ROI. .. GENERATED FROM PYTHON SOURCE LINES 11-45 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/quickflat/images/sphx_glr_plot_zoom_to_roi_001.png :alt: plot zoom to roi :srcset: /auto_examples/quickflat/images/sphx_glr_plot_zoom_to_roi_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/quickflat/images/sphx_glr_plot_zoom_to_roi_002.png :alt: plot zoom to roi :srcset: /auto_examples/quickflat/images/sphx_glr_plot_zoom_to_roi_002.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Failed to get connection ** (inkscape:5375): CRITICAL **: 01:30:32.250: dbus_g_proxy_new_for_name: assertion 'connection != NULL' failed ** (inkscape:5375): CRITICAL **: 01:30:32.251: dbus_g_proxy_call: assertion 'DBUS_IS_G_PROXY (proxy)' failed ** (inkscape:5375): CRITICAL **: 01:30:32.251: dbus_g_connection_register_g_object: assertion 'connection != NULL' failed Generating a flatmap cache Failed to get connection ** (inkscape:5393): CRITICAL **: 01:31:05.967: dbus_g_proxy_new_for_name: assertion 'connection != NULL' failed ** (inkscape:5393): CRITICAL **: 01:31:05.967: dbus_g_proxy_call: assertion 'DBUS_IS_G_PROXY (proxy)' failed ** (inkscape:5393): CRITICAL **: 01:31:05.967: dbus_g_connection_register_g_object: assertion 'connection != NULL' failed | .. code-block:: default # sphinx_gallery_thumbnail_number = 2 import cortex import numpy as np np.random.seed(1234) from matplotlib import pyplot as plt def zoom_to_roi(subject, roi, hem, margin=10.0): roi_verts = cortex.get_roi_verts(subject, roi)[roi] roi_map = cortex.Vertex.empty(subject) roi_map.data[roi_verts] = 1 (lflatpts, lpolys), (rflatpts, rpolys) = cortex.db.get_surf(subject, "flat", nudge=True) sel_pts = dict(left=lflatpts, right=rflatpts)[hem] roi_pts = sel_pts[np.nonzero(getattr(roi_map, hem))[0],:2] xmin, ymin = roi_pts.min(0) - margin xmax, ymax = roi_pts.max(0) + margin plt.axis([xmin, xmax, ymin, ymax]) # Create dataset data = cortex.Volume.random('S1', 'fullhead') # Plot it using quickflat cortex.quickshow(data) # Zoom on just one region zoom_to_roi('S1', 'AC', 'left') # notice that the quality of this figure is now quite poor/grainy # we can improve this by changing the 'height' argument to quickflat cortex.quickshow(data, height=2048) zoom_to_roi('S1', 'AC', 'left') .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 39.235 seconds) .. _sphx_glr_download_auto_examples_quickflat_plot_zoom_to_roi.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_zoom_to_roi.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_zoom_to_roi.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_