.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/exploratory/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_exploratory_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-14 .. code-block:: Python # Author: Amanda Hernando Bernabé # License: MIT # sphinx_gallery_thumbnail_number = 3 .. GENERATED FROM PYTHON SOURCE LINES 15-26 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 26-39 .. code-block:: Python from skfda.datasets import make_gaussian_process 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 40-43 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 43-50 .. code-block:: Python import numpy as np cube = np.repeat(fd.data_matrix, n_features).reshape( (n_samples, n_features, n_features), ) .. GENERATED FROM PYTHON SOURCE LINES 51-52 We can plot now the extruded trajectories. .. GENERATED FROM PYTHON SOURCE LINES 52-66 .. code-block:: Python import matplotlib.pyplot as plt from skfda import FDataGrid fd_2 = FDataGrid( data_matrix=cube, grid_points=np.tile(fd.grid_points, (2, 1)), dataset_name="Extruded Brownian process", ) fd_2.plot() plt.show() .. image-sg:: /auto_examples/exploratory/images/sphx_glr_plot_surface_boxplot_001.png :alt: Extruded Brownian process :srcset: /auto_examples/exploratory/images/sphx_glr_plot_surface_boxplot_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 67-76 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 76-80 .. code-block:: Python fd.plot() plt.show() .. image-sg:: /auto_examples/exploratory/images/sphx_glr_plot_surface_boxplot_002.png :alt: Brownian process :srcset: /auto_examples/exploratory/images/sphx_glr_plot_surface_boxplot_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 81-84 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 84-91 .. code-block:: Python from skfda.exploratory.visualization import SurfaceBoxplot surface_boxplot = SurfaceBoxplot(fd_2) surface_boxplot.plot() plt.show() .. image-sg:: /auto_examples/exploratory/images/sphx_glr_plot_surface_boxplot_003.png :alt: Extruded Brownian process :srcset: /auto_examples/exploratory/images/sphx_glr_plot_surface_boxplot_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 92-101 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 101-107 .. code-block:: Python from skfda.exploratory.visualization import Boxplot boxplot1 = Boxplot(fd) boxplot1.plot() plt.show() .. image-sg:: /auto_examples/exploratory/images/sphx_glr_plot_surface_boxplot_004.png :alt: Brownian process :srcset: /auto_examples/exploratory/images/sphx_glr_plot_surface_boxplot_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.557 seconds) .. _sphx_glr_download_auto_examples_exploratory_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/exploratory/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 ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_surface_boxplot.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_