.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/stereographic_projection/zoom_inset_region.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_examples_stereographic_projection_zoom_inset_region.py: ================= Zoom region inset ================= This example shows how to add a region in the stereographic projection as a zoomed inset inside another stereographic projection, following the procedure in `this Matplotlib example `__. .. GENERATED FROM PYTHON SOURCE LINES 29-83 .. image-sg:: /examples/stereographic_projection/images/sphx_glr_zoom_inset_region_001.png :alt: zoom inset region :srcset: /examples/stereographic_projection/images/sphx_glr_zoom_inset_region_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt from orix import projections, sampling from orix.plot import register_projections from orix.vector import Vector3d register_projections() # Register our custom Matplotlib projections # Sample some orientations v = sampling.sample_S2(2) v_ref = Vector3d([1, 1, 1]) v2 = v[v_ref.angle_with(v, degrees=True) < 10] # Plot them in the stereographic projection with a grid resolution of 10 # degrees fig = plt.figure(figsize=(5, 5)) ax = fig.add_subplot(111, projection="stereographic") ax.stereographic_grid(True) ax.set_labels("X", "Y", None, fontsize=20) ax.scatter(v2) ax.scatter(v_ref, c="r") # Define some vectors describing the x/y extent of the zoomed inset # region and get their stereographic coordinates (X, Y) v_inset = Vector3d.from_polar(azimuth=[45, 45], polar=[36, 71], degrees=True) stereo = projections.StereographicProjection() x_inset, y_inset = stereo.vector2xy(v_inset) # The zoomed inset rectangle origin (x, y), width and height rect = [0.15, 0.2, 0.43, 0.43] # Add a new stereographic projection axis and zoom in ax_inset = ax.inset_axes(rect, projection="stereographic") ax_inset.set( xlim=(x_inset.min(), x_inset.max()), ylim=(y_inset.min(), y_inset.max()), ) # Add a grid of 2 degrees resolution and re-plot the vectors ax_inset.stereographic_grid(True, 2, 2) ax_inset.scatter(v2) ax_inset.scatter(v_ref, c="r") # Add lines indicating the inset zoom ax.indicate_inset_zoom(ax_inset, edgecolor="k") # Add border to the inset region for spine in ax_inset.spines.values(): spine.set_visible(True) # The inset axis is not compatible with fig.tight_layout(), so we set # the origin and width and height manually fig.subplots_adjust(0, 0, 1, 1) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.342 seconds) **Estimated memory usage:** 548 MB .. _sphx_glr_download_examples_stereographic_projection_zoom_inset_region.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: zoom_inset_region.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: zoom_inset_region.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: zoom_inset_region.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_