.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/create_signal/from_tabular_data.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_auto_examples_create_signal_from_tabular_data.py: Creates a signal1D from tabular data ==================================== This example creates a signal from tabular data, where the signal axis is given by an array of data values (the ``x`` column) and the tabular data are ordered in columns with 5 columns containing each 20 values and each column corresponding to a position in the navigation space (linescan). .. GENERATED FROM PYTHON SOURCE LINES 10-14 .. code-block:: Python import numpy as np import hyperspy.api as hs .. GENERATED FROM PYTHON SOURCE LINES 15-16 Create a set of tabular data: .. GENERATED FROM PYTHON SOURCE LINES 16-20 .. code-block:: Python x = np.linspace(0, 10, 20) y = np.random.default_rng().random((20, 5)) .. GENERATED FROM PYTHON SOURCE LINES 21-22 Define the axes of the signal and then create the signal: .. GENERATED FROM PYTHON SOURCE LINES 22-32 .. code-block:: Python axes = [ # length of the navigation axis dict(size=y.shape[1], scale=0.1, name="Position", units="nm"), # use values to define non-uniform axis for the signal axis dict(axis=x, name="Energy", units="eV"), ] s = hs.signals.Signal1D(y.T, axes=axes) .. GENERATED FROM PYTHON SOURCE LINES 33-36 Convert the non-uniform signal axis to a uniform axis, because non-uniform axes do not support all functionalities of HyperSpy. In this case, the error introduced during conversion to uniform `scale` is negligeable. .. GENERATED FROM PYTHON SOURCE LINES 36-39 .. code-block:: Python s.axes_manager.signal_axes[0].convert_to_uniform_axis() .. GENERATED FROM PYTHON SOURCE LINES 40-41 Set title of the dataset and label for the data axis: .. GENERATED FROM PYTHON SOURCE LINES 41-45 .. code-block:: Python s.metadata.set_item("General.title", "Random test data") s.metadata.set_item("Signal.quantity", "Intensity (counts)") .. GENERATED FROM PYTHON SOURCE LINES 46-47 Plot the dataset: .. GENERATED FROM PYTHON SOURCE LINES 47-51 .. code-block:: Python s.plot() # Choose the second figure as gallery thumbnail: # sphinx_gallery_thumbnail_number = 2 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/create_signal/images/sphx_glr_from_tabular_data_001.png :alt: Random test data Navigator :srcset: /auto_examples/create_signal/images/sphx_glr_from_tabular_data_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/create_signal/images/sphx_glr_from_tabular_data_002.png :alt: Random test data Signal :srcset: /auto_examples/create_signal/images/sphx_glr_from_tabular_data_002.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.596 seconds) .. _sphx_glr_download_auto_examples_create_signal_from_tabular_data.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: from_tabular_data.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: from_tabular_data.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_