.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/representation/plot_discrete_representation.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. or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_representation_plot_discrete_representation.py: Discretized function representation =================================== Shows how to make a discretized representation of a function. .. GENERATED FROM PYTHON SOURCE LINES 7-13 .. code-block:: Python # Author: Carlos Ramos CarreƱo # License: MIT # sphinx_gallery_thumbnail_number = 2 .. GENERATED FROM PYTHON SOURCE LINES 14-16 We will construct a dataset containing several sinusoidal functions with random displacements. .. GENERATED FROM PYTHON SOURCE LINES 16-26 .. code-block:: Python import numpy as np random_state = np.random.RandomState(0) grid_points = np.linspace(0, 1) data = np.array([ np.sin((grid_points + random_state.randn()) * 2 * np.pi) for _ in range(5) ]) .. GENERATED FROM PYTHON SOURCE LINES 27-29 The FDataGrid class is used for datasets containing discretized functions that are measured at the same points. .. GENERATED FROM PYTHON SOURCE LINES 29-41 .. code-block:: Python from skfda import FDataGrid fd = FDataGrid( data, grid_points, dataset_name="Sinusoidal curves", argument_names=["t"], coordinate_names=["x(t)"], ) fd = fd[:5] .. GENERATED FROM PYTHON SOURCE LINES 42-43 We can plot the measured values of each function in a scatter plot. .. GENERATED FROM PYTHON SOURCE LINES 43-48 .. code-block:: Python import matplotlib.pyplot as plt fd.scatter(s=0.5) plt.show() .. image-sg:: /auto_examples/representation/images/sphx_glr_plot_discrete_representation_001.png :alt: Sinusoidal curves :srcset: /auto_examples/representation/images/sphx_glr_plot_discrete_representation_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 49-50 We can also plot the interpolated functions. .. GENERATED FROM PYTHON SOURCE LINES 50-53 .. code-block:: Python fd.plot() plt.show() .. image-sg:: /auto_examples/representation/images/sphx_glr_plot_discrete_representation_002.png :alt: Sinusoidal curves :srcset: /auto_examples/representation/images/sphx_glr_plot_discrete_representation_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.118 seconds) .. _sphx_glr_download_auto_examples_representation_plot_discrete_representation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/GAA-UAM/scikit-fda/develop?filepath=examples/representation/plot_discrete_representation.py :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_discrete_representation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_discrete_representation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_discrete_representation.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_