.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_tutorials/1D_datasets/plot_0_1D.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_tutorials_1D_datasets_plot_0_1D.py: 1D{1} datasets -------------- .. GENERATED FROM PYTHON SOURCE LINES 6-8 In the following example, we illustrate how one can covert a Numpy array into a CSDM object. Start by importing the Numpy and csdmpy libraries. .. GENERATED FROM PYTHON SOURCE LINES 8-13 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import csdmpy as cp .. GENERATED FROM PYTHON SOURCE LINES 14-15 Let's generate a 1D NumPy array of as our dataset. .. GENERATED FROM PYTHON SOURCE LINES 15-18 .. code-block:: Python test_data = np.zeros(500) test_data[250] = 1 .. GENERATED FROM PYTHON SOURCE LINES 19-20 Create a DependentVariable object from the numpy object .. GENERATED FROM PYTHON SOURCE LINES 20-22 .. code-block:: Python dv = cp.as_dependent_variable(test_data, unit="%") .. GENERATED FROM PYTHON SOURCE LINES 23-24 Create the corresponding dimensions object. Here, we create a LinearDimension object .. GENERATED FROM PYTHON SOURCE LINES 24-26 .. code-block:: Python dim = cp.LinearDimension(count=500, increment="1 m") .. GENERATED FROM PYTHON SOURCE LINES 27-28 Creating the CSDM object. .. GENERATED FROM PYTHON SOURCE LINES 28-30 .. code-block:: Python csdm_object = cp.CSDM(dependent_variables=[dv], dimensions=[dim]) .. GENERATED FROM PYTHON SOURCE LINES 31-32 Plot of the dataset. .. GENERATED FROM PYTHON SOURCE LINES 32-38 .. code-block:: Python plt.figure(figsize=(5, 3.5)) ax = plt.subplot(projection="csdm") ax.plot(csdm_object) plt.tight_layout() plt.show() .. image-sg:: /auto_tutorials/1D_datasets/images/sphx_glr_plot_0_1D_001.png :alt: plot 0 1D :srcset: /auto_tutorials/1D_datasets/images/sphx_glr_plot_0_1D_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 39-40 To serialize the file, use the save method. .. GENERATED FROM PYTHON SOURCE LINES 40-41 .. code-block:: Python csdm_object.save("1D_1_dataset.csdf") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.187 seconds) .. _sphx_glr_download_auto_tutorials_1D_datasets_plot_0_1D.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_0_1D.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_0_1D.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_