.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/dataset/visualization/plot_boxplot.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_dataset_visualization_plot_boxplot.py: Boxplot ======= .. GENERATED FROM PYTHON SOURCE LINES 25-36 .. code-block:: default from __future__ import annotations from gemseo.api import configure_logger from gemseo.core.dataset import Dataset from gemseo.post.dataset.boxplot import Boxplot from numpy import hstack from numpy import linspace configure_logger() .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 37-39 Build a dataset --------------- .. GENERATED FROM PYTHON SOURCE LINES 39-53 .. code-block:: default inputs = linspace(-1, 1, 100)[:, None] dataset = Dataset(name="Foo") dataset.add_variable("y1", inputs**2, "outputs", cache_as_input=False) dataset.add_variable( "y2", hstack((inputs**3, inputs**4)), "outputs", cache_as_input=False ) other_dataset = Dataset(name="Bar") other_dataset.add_variable("y1", -(inputs**2), "outputs", cache_as_input=False) other_dataset.add_variable( "y2", hstack((-(inputs**3), -(inputs**4))), "outputs", cache_as_input=False ) .. GENERATED FROM PYTHON SOURCE LINES 54-57 Plot y1 and y2 -------------- We can use the :class:`.Boxplot` plot. .. GENERATED FROM PYTHON SOURCE LINES 57-63 .. code-block:: default plot = Boxplot(dataset) plot.xlabel = "Variables" plot.ylabel = "Values" plot.title = "Standard boxplots" plot.execute(save=False, show=True) .. image-sg:: /examples/dataset/visualization/images/sphx_glr_plot_boxplot_001.png :alt: Standard boxplots :srcset: /examples/dataset/visualization/images/sphx_glr_plot_boxplot_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [
] .. GENERATED FROM PYTHON SOURCE LINES 64-67 Plot with centering ------------------- We can center the data: .. GENERATED FROM PYTHON SOURCE LINES 67-71 .. code-block:: default plot = Boxplot(dataset, center=True) plot.title = "With centering" plot.execute(save=False, show=True) .. image-sg:: /examples/dataset/visualization/images/sphx_glr_plot_boxplot_002.png :alt: With centering :srcset: /examples/dataset/visualization/images/sphx_glr_plot_boxplot_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [
] .. GENERATED FROM PYTHON SOURCE LINES 72-75 Plot with scaling ----------------- We can scale the data (normalization with the standard deviation): .. GENERATED FROM PYTHON SOURCE LINES 75-79 .. code-block:: default plot = Boxplot(dataset, scale=True) plot.title = "With scaling" plot.execute(save=False, show=True) .. image-sg:: /examples/dataset/visualization/images/sphx_glr_plot_boxplot_003.png :alt: With scaling :srcset: /examples/dataset/visualization/images/sphx_glr_plot_boxplot_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [
] .. GENERATED FROM PYTHON SOURCE LINES 80-83 Plot without outliers --------------------- We can remove the outliers: .. GENERATED FROM PYTHON SOURCE LINES 83-87 .. code-block:: default plot = Boxplot(dataset, add_outliers=False) plot.title = "Without outliers" plot.execute(save=False, show=True) .. image-sg:: /examples/dataset/visualization/images/sphx_glr_plot_boxplot_004.png :alt: Without outliers :srcset: /examples/dataset/visualization/images/sphx_glr_plot_boxplot_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [
] .. GENERATED FROM PYTHON SOURCE LINES 88-91 Plot with confidence intervals ------------------------------ We can add confidence intervals for the median: .. GENERATED FROM PYTHON SOURCE LINES 91-95 .. code-block:: default plot = Boxplot(dataset, add_confidence_interval=True) plot.title = "Confidence intervals" plot.execute(save=False, show=True) .. image-sg:: /examples/dataset/visualization/images/sphx_glr_plot_boxplot_005.png :alt: Confidence intervals :srcset: /examples/dataset/visualization/images/sphx_glr_plot_boxplot_005.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [
] .. GENERATED FROM PYTHON SOURCE LINES 96-99 Plot horizontally ----------------- We can use horizontal bars: .. GENERATED FROM PYTHON SOURCE LINES 99-103 .. code-block:: default plot = Boxplot(dataset, use_vertical_bars=False) plot.title = "Horizontal bars" plot.execute(save=False, show=True) .. image-sg:: /examples/dataset/visualization/images/sphx_glr_plot_boxplot_006.png :alt: Horizontal bars :srcset: /examples/dataset/visualization/images/sphx_glr_plot_boxplot_006.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [
] .. GENERATED FROM PYTHON SOURCE LINES 104-107 Plot with other datasets ------------------------ We can add a dataset: .. GENERATED FROM PYTHON SOURCE LINES 107-110 .. code-block:: default plot = Boxplot(dataset, other_dataset) plot.title = "Additional dataset" plot.execute(save=False, show=True) .. image-sg:: /examples/dataset/visualization/images/sphx_glr_plot_boxplot_007.png :alt: Additional dataset :srcset: /examples/dataset/visualization/images/sphx_glr_plot_boxplot_007.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 0.975 seconds) .. _sphx_glr_download_examples_dataset_visualization_plot_boxplot.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_boxplot.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_boxplot.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_