.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/reference_frames/plot_detector_sample_views.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_reference_frames_plot_detector_sample_views.py: ============================== Detector-sample geometry views ============================== This example shows how to plot multiple views of the detector-sample geometry in a single figure using the :class:`~kikuchipy.detectors.EBSDDetector`. Both a side view and top view are available. These can be useful when demonstrating variations in geometry parameters in a single figure. For a more in-depth tutorial on the various reference frames in kikuchipy, see the :doc:`reference frames tutorial `. .. note:: The side view shows changes to the following geometry parameters: - :attr:`~kikuchipy.detectors.EBSDDetector.tilt` - :attr:`~kikuchipy.detectors.EBSDDetector.sample_tilt` - :attr:`~kikuchipy.detectors.EBSDDetector.pcy` - :attr:`~kikuchipy.detectors.EBSDDetector.pcz` The top view shows changes to the following geometry parameters: - :attr:`~kikuchipy.detectors.EBSDDetector.sample_tilt` - :attr:`~kikuchipy.detectors.EBSDDetector.tilt` - :attr:`~kikuchipy.detectors.EBSDDetector.azimuthal` - :attr:`~kikuchipy.detectors.EBSDDetector.pcx` - :attr:`~kikuchipy.detectors.EBSDDetector.pcy` - :attr:`~kikuchipy.detectors.EBSDDetector.pcz` None of these views show changes in the detector :attr:`~kikuchipy.detectors.EBSDDetector.twist` angle. .. note:: Use :class:`~kikuchipy.draw.EBSDDetectorPlotter` for a plot where all detector-sample geometry parameters can be changed interactively. .. GENERATED FROM PYTHON SOURCE LINES 63-64 Imports and some reusable functions. .. GENERATED FROM PYTHON SOURCE LINES 64-93 .. code-block:: Python import matplotlib.pyplot as plt import kikuchipy as kp def tilt_string(detector: kp.detectors.EBSDDetector, fmt: str = "short") -> str: if fmt == "long": return ( rf"Sample tilt $\sigma = {detector.sample_tilt:.1f}$" "\N{DEGREE SIGN}\n" rf"Detector tilt $\theta = {detector.tilt:.1f}$" "\N{DEGREE SIGN}" ) else: return ( r"($\sigma$, $\theta$) = " f"({detector.sample_tilt:.1f}" "\N{DEGREE SIGN}, " f"{detector.tilt:.1f}" "\N{DEGREE SIGN})" ) def pc_string(detector: kp.detectors.EBSDDetector) -> str: pcx, pcy, pcz = detector.pc_average.round(2) return f"(PCx, PCy, PCz) = ({pcx}, {pcy}, {pcz})" .. GENERATED FROM PYTHON SOURCE LINES 94-95 Get the default detector with a rectangular shape. .. GENERATED FROM PYTHON SOURCE LINES 95-99 .. code-block:: Python shape = (75, 100) det1 = kp.detectors.EBSDDetector(shape) print(det1) .. rst-class:: sphx-glr-script-out .. code-block:: none EBSDDetector shape (Ny, Nx): (75, 100) pc (PCx, PCy, PCz): (0.5, 0.5, 0.5) sample_tilt: 70.0° tilt: 0.0° azimuthal: 0.0° twist: 0.0° binning: 1 px_size: 1.0 um .. GENERATED FROM PYTHON SOURCE LINES 100-101 And view the detector-sample geometry. .. GENERATED FROM PYTHON SOURCE LINES 101-104 .. code-block:: Python fig = det1.plot_side_view(legend=True, return_figure=True) _ = fig.suptitle(f"Default detector-sample geometry\n{tilt_string(det1, fmt='long')}") .. image-sg:: /examples/reference_frames/images/sphx_glr_plot_detector_sample_views_001.png :alt: Default detector-sample geometry Sample tilt $\sigma = 70.0$° Detector tilt $\theta = 0.0$° :srcset: /examples/reference_frames/images/sphx_glr_plot_detector_sample_views_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 105-107 Changing sample tilt ==================== .. GENERATED FROM PYTHON SOURCE LINES 107-122 .. code-block:: Python det2 = kp.detectors.EBSDDetector(shape) fig = plt.figure(figsize=(9, 6), layout="constrained") for i, stilt in enumerate([0, 45, 90]): det2.sample_tilt = stilt ax1 = fig.add_subplot(2, 3, i + 1) ax1.set_title("Side view\n" + tilt_string(det2)) det2.plot_side_view(ax=ax1) ax2 = fig.add_subplot(2, 3, i + 4) ax2.set_title("Top view") det2.plot_top_view(ax=ax2) .. image-sg:: /examples/reference_frames/images/sphx_glr_plot_detector_sample_views_002.png :alt: Side view ($\sigma$, $\theta$) = (0.0°, 0.0°), Top view, Side view ($\sigma$, $\theta$) = (45.0°, 0.0°), Top view, Side view ($\sigma$, $\theta$) = (90.0°, 0.0°), Top view :srcset: /examples/reference_frames/images/sphx_glr_plot_detector_sample_views_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 123-125 Changing detector tilt ====================== .. GENERATED FROM PYTHON SOURCE LINES 125-140 .. code-block:: Python det3 = kp.detectors.EBSDDetector(shape) fig = plt.figure(figsize=(9, 6), layout="constrained") for i, tilt in enumerate([0, 45, 90]): det3.tilt = tilt ax1 = fig.add_subplot(2, 3, i + 1) ax1.set_title("Side view\n" + tilt_string(det3)) det3.plot_side_view(ax=ax1) ax2 = fig.add_subplot(2, 3, i + 4) ax2.set_title("Top view") det3.plot_top_view(ax=ax2) .. image-sg:: /examples/reference_frames/images/sphx_glr_plot_detector_sample_views_003.png :alt: Side view ($\sigma$, $\theta$) = (70.0°, 0.0°), Top view, Side view ($\sigma$, $\theta$) = (70.0°, 45.0°), Top view, Side view ($\sigma$, $\theta$) = (70.0°, 90.0°), Top view :srcset: /examples/reference_frames/images/sphx_glr_plot_detector_sample_views_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 141-146 Changing sample and detector tilts ================================== Let's start with the sample tilt at :math:`\sigma = 90^{\circ}` and then decrease it while increasing the detector tilt :math:`\theta` in steps of :math:`10^{\circ}`. .. GENERATED FROM PYTHON SOURCE LINES 146-165 .. code-block:: Python det4 = kp.detectors.EBSDDetector(shape) sample_tilts = [90, 45, 0] detector_tilts = sample_tilts[::-1] fig = plt.figure(figsize=(9, 6), layout="constrained") for i, (stilt, tilt) in enumerate(zip(sample_tilts, detector_tilts)): det4.sample_tilt = stilt det4.tilt = tilt ax1 = fig.add_subplot(2, 3, i + 1) ax1.set_title("Side view\n" + tilt_string(det4)) det4.plot_side_view(ax=ax1) ax2 = fig.add_subplot(2, 3, i + 4) ax2.set_title("Top view") det4.plot_top_view(ax=ax2) .. image-sg:: /examples/reference_frames/images/sphx_glr_plot_detector_sample_views_004.png :alt: Side view ($\sigma$, $\theta$) = (90.0°, 0.0°), Top view, Side view ($\sigma$, $\theta$) = (45.0°, 45.0°), Top view, Side view ($\sigma$, $\theta$) = (0.0°, 90.0°), Top view :srcset: /examples/reference_frames/images/sphx_glr_plot_detector_sample_views_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 166-171 Changing projection center ========================== See the documentation for the :class:`~kikuchipy.detectors.EBSDDetector` for a definition of the projection center (PC). .. GENERATED FROM PYTHON SOURCE LINES 173-177 Changing PCx ------------ Vary PCx from :math:`0 \rightarrow 1` (left :math:`\rightarrow` right). .. GENERATED FROM PYTHON SOURCE LINES 177-188 .. code-block:: Python det5 = kp.detectors.EBSDDetector(shape) fig = plt.figure(figsize=(9, 3), layout="constrained") for i, pcx in enumerate([0, 0.5, 1]): det5.pcx = pcx ax = fig.add_subplot(1, 3, i + 1) ax.set_title("Top view\n" + pc_string(det5)) det5.plot_top_view(ax=ax) .. image-sg:: /examples/reference_frames/images/sphx_glr_plot_detector_sample_views_005.png :alt: Top view (PCx, PCy, PCz) = (0.0, 0.5, 0.5), Top view (PCx, PCy, PCz) = (0.5, 0.5, 0.5), Top view (PCx, PCy, PCz) = (1.0, 0.5, 0.5) :srcset: /examples/reference_frames/images/sphx_glr_plot_detector_sample_views_005.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 189-193 Changing PCy ------------ Vary PCy from :math:`0 \rightarrow 1` (top :math:`\rightarrow` bottom). .. GENERATED FROM PYTHON SOURCE LINES 193-204 .. code-block:: Python det6 = kp.detectors.EBSDDetector(shape) fig = plt.figure(figsize=(9, 3), layout="constrained") for i, pcy in enumerate([0, 0.5, 1]): det6.pcy = pcy ax = fig.add_subplot(1, 3, i + 1) ax.set_title("Side view\n" + pc_string(det6)) det6.plot_side_view(ax=ax) .. image-sg:: /examples/reference_frames/images/sphx_glr_plot_detector_sample_views_006.png :alt: Side view (PCx, PCy, PCz) = (0.5, 0.0, 0.5), Side view (PCx, PCy, PCz) = (0.5, 0.5, 0.5), Side view (PCx, PCy, PCz) = (0.5, 1.0, 0.5) :srcset: /examples/reference_frames/images/sphx_glr_plot_detector_sample_views_006.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 205-209 Changing PCz ------------ Vary PCz from :math:`0.2 \rightarrow 1` (increasing distance from the detector) .. GENERATED FROM PYTHON SOURCE LINES 209-223 .. code-block:: Python det7 = kp.detectors.EBSDDetector(shape) fig = plt.figure(figsize=(9, 6), layout="constrained") for i, pcz in enumerate([0.2, 0.6, 1]): det7.pcz = pcz ax1 = fig.add_subplot(2, 3, i + 1) ax1.set_title("Side view\n" + pc_string(det7)) det7.plot_side_view(ax=ax1) ax2 = fig.add_subplot(2, 3, i + 4) ax2.set_title("Top view") det7.plot_top_view(ax=ax2) .. image-sg:: /examples/reference_frames/images/sphx_glr_plot_detector_sample_views_007.png :alt: Side view (PCx, PCy, PCz) = (0.5, 0.5, 0.2), Top view, Side view (PCx, PCy, PCz) = (0.5, 0.5, 0.6), Top view, Side view (PCx, PCy, PCz) = (0.5, 0.5, 1.0), Top view :srcset: /examples/reference_frames/images/sphx_glr_plot_detector_sample_views_007.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.946 seconds) **Estimated memory usage:** 790 MB .. _sphx_glr_download_examples_reference_frames_plot_detector_sample_views.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_detector_sample_views.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_detector_sample_views.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_detector_sample_views.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_