.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/plotting/color_scatter_plots.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_color_scatter_plots.py: =================== Color scatter plots =================== This example shows different ways to color vectors and (mis)orientations in scatter plots. .. GENERATED FROM PYTHON SOURCE LINES 27-40 .. code-block:: Python import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np from orix.plot import register_projections from orix.quaternion import Orientation from orix.quaternion.symmetry import Oh from orix.vector import Vector3d register_projections() # Register our custom Matplotlib projections np.random.seed(2319) # Create reproducible random data .. GENERATED FROM PYTHON SOURCE LINES 41-47 Create some random vectors and plot them in the stereographic projection, coloring by: - Scalar values mapped to a Matplotlib color map - Pre-computed RGBA colormapping from a Matplotlib color map - RGB values - A single color .. GENERATED FROM PYTHON SOURCE LINES 47-73 .. code-block:: Python v = Vector3d.random(50) c_scalar = np.linspace(0, 1, v.size) c_rgba = mpl.colormaps["viridis"](c_scalar) c_rgb = np.random.random(v.size * 3).reshape(v.size, 3) c_color = "xkcd:salmon" n = 4 fig = plt.figure(figsize=(n * 3, n), layout="constrained") ax0 = fig.add_subplot(1, n, 1, projection="stereographic") ax0.scatter(v, c=c_scalar, cmap="inferno") ax0.set_title("Scalars mapped to colormap") ax1 = fig.add_subplot(1, n, 2, projection="stereographic") ax1.scatter(v, c=c_rgba) ax1.set_title("Pre-computed RGBA colormap") ax2 = fig.add_subplot(1, n, 3, projection="stereographic") ax2.scatter(v, c=c_rgb) ax2.set_title("Pre-computed RGB values") ax3 = fig.add_subplot(1, n, 4, projection="stereographic") ax3.scatter(v, c=c_color) _ = ax3.set_title("A single color") .. image-sg:: /examples/plotting/images/sphx_glr_color_scatter_plots_001.png :alt: Scalars mapped to colormap, Pre-computed RGBA colormap, Pre-computed RGB values, A single color :srcset: /examples/plotting/images/sphx_glr_color_scatter_plots_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 74-75 This also works nicely when coloring (mis)orientations .. GENERATED FROM PYTHON SOURCE LINES 75-95 .. code-block:: Python ori = Orientation.random(50) ori.symmetry = Oh n = 4 fig = plt.figure(figsize=(n * 3, n), layout="tight") scatter_kwargs = {"projection": "axangle", "figure": fig} ori.scatter(c=c_scalar, cmap="inferno", position=(1, n, 1), **scatter_kwargs) fig.axes[0].set_title("Scalars mapped to colormap") ori.scatter(c=c_rgba, position=(1, n, 2), **scatter_kwargs) fig.axes[1].set_title("Pre-computed RGBA colormap") ori.scatter(c=c_rgb, position=(1, n, 3), **scatter_kwargs) fig.axes[2].set_title("Pre-computed RGB values") ori.scatter(c=c_color, position=(1, n, 4), **scatter_kwargs) _ = fig.axes[3].set_title("A single color") plt.show() .. image-sg:: /examples/plotting/images/sphx_glr_color_scatter_plots_002.png :alt: Scalars mapped to colormap, Pre-computed RGBA colormap, Pre-computed RGB values, A single color :srcset: /examples/plotting/images/sphx_glr_color_scatter_plots_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.478 seconds) **Estimated memory usage:** 583 MB .. _sphx_glr_download_examples_plotting_color_scatter_plots.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: color_scatter_plots.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: color_scatter_plots.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: color_scatter_plots.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_