.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_tutorials/1D_datasets/plot_1_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_1_1D.py: 1D{1,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 two 1D NumPy arrays as the dependent variables of as our dataset. .. GENERATED FROM PYTHON SOURCE LINES 15-21 .. code-block:: Python test_data1 = np.zeros(500) test_data1[250] = 1 test_data2 = np.zeros(500) test_data2[150] = 1 .. GENERATED FROM PYTHON SOURCE LINES 22-23 Create the two DependentVariable objects from the numpy objects. .. GENERATED FROM PYTHON SOURCE LINES 23-26 .. code-block:: Python dv1 = cp.as_dependent_variable(test_data1, unit="%") dv2 = cp.as_dependent_variable(test_data2, unit="J") .. GENERATED FROM PYTHON SOURCE LINES 27-28 Create the corresponding dimension object. Here, we create a LinearDimension object. .. GENERATED FROM PYTHON SOURCE LINES 28-30 .. code-block:: Python dim = cp.LinearDimension(count=500, increment="43 cm", coordinates_offset="-0.1 km") .. GENERATED FROM PYTHON SOURCE LINES 31-32 Creating the CSDM object. .. GENERATED FROM PYTHON SOURCE LINES 32-34 .. code-block:: Python csdm_object = cp.CSDM(dependent_variables=[dv1, dv2], dimensions=[dim]) .. GENERATED FROM PYTHON SOURCE LINES 35-36 Plot of the dataset. .. GENERATED FROM PYTHON SOURCE LINES 36-42 .. 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_1_1D_001.png :alt: plot 1 1D :srcset: /auto_tutorials/1D_datasets/images/sphx_glr_plot_1_1D_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 43-44 To serialize the file, use the save method. .. GENERATED FROM PYTHON SOURCE LINES 44-45 .. code-block:: Python csdm_object.save("1D_11_dataset.csdf") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.208 seconds) .. _sphx_glr_download_auto_tutorials_1D_datasets_plot_1_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_1_1D.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_1_1D.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_