.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/plotting/plotting_a_diffraction_pattern.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_plotting_plotting_a_diffraction_pattern.py: Plotting a Diffraction Pattern ============================== This is sometimes not as straightforward as it seems because you might have a zero beam that is too bright and regions of the diffraction pattern that are too dark. .. GENERATED FROM PYTHON SOURCE LINES 8-13 .. code-block:: Python from pyxem.data import fe_multi_phase_grains mulit_phase = fe_multi_phase_grains() .. GENERATED FROM PYTHON SOURCE LINES 14-17 We can plot easily using the `plot` method. This will show the diffraction pattern but the plot is static and not interactive. Additionally, the zero beam is too bright and the high k values are too dark. .. GENERATED FROM PYTHON SOURCE LINES 17-20 .. code-block:: Python mulit_phase.plot() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/plotting/images/sphx_glr_plotting_a_diffraction_pattern_001.png :alt: plotting a diffraction pattern :srcset: /examples/plotting/images/sphx_glr_plotting_a_diffraction_pattern_001.png :class: sphx-glr-multi-img * .. image-sg:: /examples/plotting/images/sphx_glr_plotting_a_diffraction_pattern_002.png :alt: Signal :srcset: /examples/plotting/images/sphx_glr_plotting_a_diffraction_pattern_002.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 21-23 Plotting the diffraction pattern with a logarithmic scale can help to see the high k values But because most of the values are zero, the contrast is not great and is too stretched. .. GENERATED FROM PYTHON SOURCE LINES 23-26 .. code-block:: Python mulit_phase.plot(norm="log") .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/plotting/images/sphx_glr_plotting_a_diffraction_pattern_003.png :alt: plotting a diffraction pattern :srcset: /examples/plotting/images/sphx_glr_plotting_a_diffraction_pattern_003.png :class: sphx-glr-multi-img * .. image-sg:: /examples/plotting/images/sphx_glr_plotting_a_diffraction_pattern_004.png :alt: Signal :srcset: /examples/plotting/images/sphx_glr_plotting_a_diffraction_pattern_004.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 27-30 You can also use the `symlog` norm to plot the diffraction pattern with a logarithmic scale but with a linear scale around zero. This can be useful to see the zero beam and the high k values. additionally you can visualize negative and positive values as well. .. GENERATED FROM PYTHON SOURCE LINES 30-33 .. code-block:: Python mulit_phase.plot(norm="symlog") .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/plotting/images/sphx_glr_plotting_a_diffraction_pattern_005.png :alt: plotting a diffraction pattern :srcset: /examples/plotting/images/sphx_glr_plotting_a_diffraction_pattern_005.png :class: sphx-glr-multi-img * .. image-sg:: /examples/plotting/images/sphx_glr_plotting_a_diffraction_pattern_006.png :alt: Signal :srcset: /examples/plotting/images/sphx_glr_plotting_a_diffraction_pattern_006.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 34-38 We can also set vmin and vmax to control the contrast. This can be useful to see the high k values. A very useful feature is the ability to plot the diffraction pattern with vmax set to the 99th percentile. This sets the maximum value to the 99th percentile of the data. In general this works better than setting norm='log' if you have zero values in the diffraction pattern. .. GENERATED FROM PYTHON SOURCE LINES 38-41 .. code-block:: Python mulit_phase.plot(vmax="99th") .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/plotting/images/sphx_glr_plotting_a_diffraction_pattern_007.png :alt: plotting a diffraction pattern :srcset: /examples/plotting/images/sphx_glr_plotting_a_diffraction_pattern_007.png :class: sphx-glr-multi-img * .. image-sg:: /examples/plotting/images/sphx_glr_plotting_a_diffraction_pattern_008.png :alt: Signal :srcset: /examples/plotting/images/sphx_glr_plotting_a_diffraction_pattern_008.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 42-43 We can also use a gamma correction to control and optimize the contrast. .. GENERATED FROM PYTHON SOURCE LINES 43-47 .. code-block:: Python mulit_phase.plot(norm="power", gamma=0.4) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/plotting/images/sphx_glr_plotting_a_diffraction_pattern_009.png :alt: plotting a diffraction pattern :srcset: /examples/plotting/images/sphx_glr_plotting_a_diffraction_pattern_009.png :class: sphx-glr-multi-img * .. image-sg:: /examples/plotting/images/sphx_glr_plotting_a_diffraction_pattern_010.png :alt: Signal :srcset: /examples/plotting/images/sphx_glr_plotting_a_diffraction_pattern_010.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 48-51 Note: that any of the plots are interactive if you add: %matplotlib ipympl or %matplotlib qt at the beginning of a Jupyter notebook cell. %matplotlib inline will make the plots static. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.280 seconds) .. _sphx_glr_download_examples_plotting_plotting_a_diffraction_pattern.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plotting_a_diffraction_pattern.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plotting_a_diffraction_pattern.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plotting_a_diffraction_pattern.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_