.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_surface_boxplot.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_plot_surface_boxplot.py: Surface Boxplot ==================== Shows the use of the surface boxplot, which is a generalization of the functional boxplot for FDataGrid whose domain dimension is 2. .. GENERATED FROM PYTHON SOURCE LINES 8-22 .. code-block:: Python # Author: Amanda Hernando Bernabé # License: MIT # sphinx_gallery_thumbnail_number = 3 from skfda import FDataGrid from skfda.datasets import make_gaussian_process from skfda.exploratory.visualization import SurfaceBoxplot, Boxplot import matplotlib.pyplot as plt import numpy as np .. GENERATED FROM PYTHON SOURCE LINES 23-34 In order to instantiate a :class:`~skfda.exploratory.visualization.SurfaceBoxplot`, a functional data object with bidimensional domain must be generated. In this example, a FDataGrid representing a function :math:`f : \mathbb{R}^2\longmapsto\mathbb{R}` is constructed, using as an example a Brownian process extruded into another dimension. The values of the Brownian process are generated using :func:`~skfda.datasets.make_gaussian_process`, Those functions return FDataGrid objects whose ``data_matrix`` store the values needed. .. GENERATED FROM PYTHON SOURCE LINES 34-41 .. code-block:: Python n_samples = 10 n_features = 10 fd = make_gaussian_process(n_samples=n_samples, n_features=n_features, random_state=1) fd.dataset_name = "Brownian process" .. GENERATED FROM PYTHON SOURCE LINES 42-45 After, those values generated for one dimension on the domain are extruded along another dimension, obtaining a three-dimensional matrix or cube (two-dimensional domain and one-dimensional image). .. GENERATED FROM PYTHON SOURCE LINES 45-49 .. code-block:: Python cube = np.repeat(fd.data_matrix, n_features).reshape( (n_samples, n_features, n_features)) .. GENERATED FROM PYTHON SOURCE LINES 50-51 We can plot now the extruded trajectories. .. GENERATED FROM PYTHON SOURCE LINES 51-58 .. code-block:: Python fd_2 = FDataGrid(data_matrix=cube, grid_points=np.tile(fd.grid_points, (2, 1)), dataset_name="Extruded Brownian process") fd_2.plot() .. image-sg:: /auto_examples/images/sphx_glr_plot_surface_boxplot_001.png :alt: Extruded Brownian process :srcset: /auto_examples/images/sphx_glr_plot_surface_boxplot_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 59-68 Since matplotlib was initially designed with only two-dimensional plotting in mind, the three-dimensional plotting utilities were built on top of matplotlib's two-dimensional display, and the result is a convenient (if somewhat limited) set of tools for three-dimensional data visualization as we can observe. For this reason, the profiles of the surfaces, which are contained in the first two generated functional data objects, are plotted below, to help to visualize the data. .. GENERATED FROM PYTHON SOURCE LINES 68-71 .. code-block:: Python fd.plot() .. image-sg:: /auto_examples/images/sphx_glr_plot_surface_boxplot_002.png :alt: Brownian process :srcset: /auto_examples/images/sphx_glr_plot_surface_boxplot_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 72-75 To terminate the example, the instantiation of the :class:`~skfda.exploratory.visualization.SurfaceBoxplot` object is made, showing the surface boxplot which corresponds to our FDataGrid .. GENERATED FROM PYTHON SOURCE LINES 75-79 .. code-block:: Python surfaceBoxplot = SurfaceBoxplot(fd_2) surfaceBoxplot.plot() .. image-sg:: /auto_examples/images/sphx_glr_plot_surface_boxplot_003.png :alt: Extruded Brownian process :srcset: /auto_examples/images/sphx_glr_plot_surface_boxplot_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 80-89 The surface boxplot contains the median, the central envelope and the outlying envelope plotted from darker to lighter colors, although they can be customized. Analogous to the procedure followed before of plotting the three-dimensional data and their correponding profiles, we can obtain also the functional boxplot for one-dimensional data with the :class:`~skfda.exploratory.visualization.Boxplot` passing as arguments the first FdataGrid object. The profile of the surface boxplot is obtained. .. GENERATED FROM PYTHON SOURCE LINES 89-92 .. code-block:: Python boxplot1 = Boxplot(fd) boxplot1.plot() .. image-sg:: /auto_examples/images/sphx_glr_plot_surface_boxplot_004.png :alt: Brownian process :srcset: /auto_examples/images/sphx_glr_plot_surface_boxplot_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.027 seconds) .. _sphx_glr_download_auto_examples_plot_surface_boxplot.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/plot_surface_boxplot.py :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_surface_boxplot.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_surface_boxplot.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_