.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/reference_frames/interactive_ebsd_detector_plotter.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_interactive_ebsd_detector_plotter.py: ================================= Interactive EBSD detector plotter ================================= This example shows how to set up an interactive plot showing the side and top view of the microscope as well as the detector plane and the effects of changing detector-sample geometry parameters as well as the crystal orientation. We use the :class:`~kikuchipy.draw.EBSDDetectorPlotter`. .. note:: The plotter requires :doc:`ipywidgets ` to be installed. Interactivity is only achieved when run in an active Jupyter session, not directly on this static web page. Run locally with an interactive Matplotlib backend. .. GENERATED FROM PYTHON SOURCE LINES 41-42 Imports. .. GENERATED FROM PYTHON SOURCE LINES 42-52 .. code-block:: Python from diffsims.crystallography import ReciprocalLatticeVector from IPython.display import display import matplotlib import matplotlib.pyplot as plt import kikuchipy as kp matplotlib.use("ipympl") _ = plt.ion() .. GENERATED FROM PYTHON SOURCE LINES 53-54 Load a small (not large) nickel EBSD map. .. GENERATED FROM PYTHON SOURCE LINES 54-57 .. code-block:: Python s = kp.data.nickel_ebsd_large() print(s) .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 58-59 The EBSD dataset has both a crystal map and detector attached. .. GENERATED FROM PYTHON SOURCE LINES 59-65 .. code-block:: Python xmap = s.xmap print(xmap) det = s.detector print(det) .. rst-class:: sphx-glr-script-out .. code-block:: none Phase Orientations Name Space group Point group Proper point group Color 0 4125 (100.0%) ni Fm-3m m-3m 432 tab:blue Properties: scores, z Scan unit: um EBSDDetector shape (Ny, Nx): (60, 60) pc (PCx, PCy, PCz): (0.423, 0.214, 0.502) sample_tilt: 70.0° tilt: 0.0° azimuthal: 0.0° twist: 0.0° binning: 8 px_size: 1.0 um .. GENERATED FROM PYTHON SOURCE LINES 66-67 Load the builtin nickel master pattern (of low resolution). .. GENERATED FROM PYTHON SOURCE LINES 67-70 .. code-block:: Python mp = kp.data.nickel_ebsd_master_pattern_small(projection="lambert", energy=20) print(mp) .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 71-72 Set up a reflector list and pick a rotation from the crystal map. .. GENERATED FROM PYTHON SOURCE LINES 72-83 .. code-block:: Python phase = xmap.phases[0] print(phase) ref0 = ReciprocalLatticeVector( phase=phase, hkl=[[1, 1, 1], [2, 0, 0], [2, 2, 0], [3, 1, 1]] ) ref0.sanitise_phase() ref = ref0.symmetrise().unique() rot = s.xmap.rotations[0] .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 84-85 Create a plotter and add the geometrical and dynamical simulations. .. GENERATED FROM PYTHON SOURCE LINES 85-90 .. code-block:: Python pl = kp.draw.EBSDDetectorPlotter(detector=det, rotation=rot, inplace=True) pl.set_geometrical_simulation(reflectors=ref) pl.set_master_pattern(mp) print(pl) .. rst-class:: sphx-glr-script-out .. code-block:: none EBSDDetectorPlotter(inplace=True) shape (Ny, Nx): (60, 60) pc (PCx, PCy, PCz): (0.423, 0.214, 0.502) sample_tilt: 70.0° tilt: 0.0° azimuthal: 0.0° twist: 0.0° binning: 8 px_size: 1.0 um Geometrical simulation: ReciprocalLatticeVector (50,), ni (m-3m) Master pattern: .. GENERATED FROM PYTHON SOURCE LINES 91-92 Show the plotter and controls (when run locally). .. GENERATED FROM PYTHON SOURCE LINES 92-97 .. code-block:: Python fig, controls = pl.show(figsize=(9, 3)) display(controls) plt.show() .. image-sg:: /examples/reference_frames/images/sphx_glr_interactive_ebsd_detector_plotter_001.png :alt: Side view, Top view, Detector :srcset: /examples/reference_frames/images/sphx_glr_interactive_ebsd_detector_plotter_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none HBox(children=(VBox(children=(HTML(value='Detector-sample geometry'), FloatSlider(value=70.0, description='Sample tilt [°]', max=90.0, style=SliderStyle(description_width='initial')), FloatSlider(value=0.0, description='Detector tilt [°]', max=90.0, min=-90.0, style=SliderStyle(description_width='initial')), FloatSlider(value=0.0, description='Azimuthal [°]', max=10.0, min=-10.0, step=0.01, style=SliderStyle(description_width='initial')), FloatSlider(value=0.0, description='Twist [°]', max=10.0, min=-10.0, style=SliderStyle(description_width='initial')), FloatSlider(value=0.4232600661596353, description='PCx', max=1.0, step=0.01, style=SliderStyle(description_width='initial')), FloatSlider(value=0.2136332544638906, description='PCy', max=1.5, min=-0.5, step=0.01, style=SliderStyle(description_width='initial')), FloatSlider(value=0.5020740783903906, description='PCz', max=1.0, min=0.2, step=0.01, style=SliderStyle(description_width='initial')))), VBox(children=(HTML(value='Crystal orientation'), FloatSlider(value=356.4331553036092, description='φ1 [°]', max=360.0, style=SliderStyle(description_width='initial')), FloatSlider(value=94.72125642285175, description='Φ [°]', max=180.0, style=SliderStyle(description_width='initial')), FloatSlider(value=141.77577886513592, description='φ2 [°]', max=360.0, style=SliderStyle(description_width='initial')))), VBox(children=(HTML(value='Overlay'), Checkbox(value=True, description='PC', indent=False), Checkbox(value=False, description='Gnomonic circles', indent=False), Checkbox(value=True, description='Geometric', indent=False), Checkbox(value=True, description='Simulation', indent=False))))) Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous view', 'arrow-left', 'back'), ('Forward', 'Forward to next view', 'arrow-right', 'forward'), ('Pan', 'Left button pans, Right button zooms\nx/y fixes axis, CTRL fixes aspect', 'arrows', 'pan'), ('Zoom', 'Zoom to rectangle\nx/y fixes axis', 'square-o', 'zoom'), ('Download', 'Download plot', 'floppy-o', 'save_figure')])) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.756 seconds) **Estimated memory usage:** 812 MB .. _sphx_glr_download_examples_reference_frames_interactive_ebsd_detector_plotter.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: interactive_ebsd_detector_plotter.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: interactive_ebsd_detector_plotter.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: interactive_ebsd_detector_plotter.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_