.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/dataset/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_plot_boxplot.py: Plot - Boxplot ============== .. GENERATED FROM PYTHON SOURCE LINES 25-37 .. 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 matplotlib import pyplot as plt from numpy import hstack from numpy import linspace configure_logger() .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 38-40 Build a dataset --------------- .. GENERATED FROM PYTHON SOURCE LINES 40-54 .. 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 55-58 Plot y1 and y2 -------------- We can use the :class:`.Boxplot` plot. .. GENERATED FROM PYTHON SOURCE LINES 58-66 .. code-block:: default plot = Boxplot(dataset) plot.xlabel = "Variables" plot.ylabel = "Values" plot.title = "Standard boxplots" plot.execute(save=False, show=False) # Workaround for HTML rendering, instead of ``show=True`` plt.show() .. image-sg:: /examples/dataset/images/sphx_glr_plot_boxplot_001.png :alt: Standard boxplots :srcset: /examples/dataset/images/sphx_glr_plot_boxplot_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 67-70 Plot with centering ------------------- We can center the data: .. GENERATED FROM PYTHON SOURCE LINES 70-76 .. code-block:: default plot = Boxplot(dataset, center=True) plot.title = "With centering" plot.execute(save=False, show=False) # Workaround for HTML rendering, instead of ``show=True`` plt.show() .. image-sg:: /examples/dataset/images/sphx_glr_plot_boxplot_002.png :alt: With centering :srcset: /examples/dataset/images/sphx_glr_plot_boxplot_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 77-80 Plot with scaling ----------------- We can scale the data (normalization with the standard deviation): .. GENERATED FROM PYTHON SOURCE LINES 80-86 .. code-block:: default plot = Boxplot(dataset, scale=True) plot.title = "With scaling" plot.execute(save=False, show=False) # Workaround for HTML rendering, instead of ``show=True`` plt.show() .. image-sg:: /examples/dataset/images/sphx_glr_plot_boxplot_003.png :alt: With scaling :srcset: /examples/dataset/images/sphx_glr_plot_boxplot_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 87-90 Plot without outliers --------------------- We can remove the outliers: .. GENERATED FROM PYTHON SOURCE LINES 90-96 .. code-block:: default plot = Boxplot(dataset, add_outliers=False) plot.title = "Without outliers" plot.execute(save=False, show=False) # Workaround for HTML rendering, instead of ``show=True`` plt.show() .. image-sg:: /examples/dataset/images/sphx_glr_plot_boxplot_004.png :alt: Without outliers :srcset: /examples/dataset/images/sphx_glr_plot_boxplot_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 97-100 Plot with confidence intervals ------------------------------ We can add confidence intervals for the median: .. GENERATED FROM PYTHON SOURCE LINES 100-106 .. code-block:: default plot = Boxplot(dataset, add_confidence_interval=True) plot.title = "Confidence intervals" plot.execute(save=False, show=False) # Workaround for HTML rendering, instead of ``show=True`` plt.show() .. image-sg:: /examples/dataset/images/sphx_glr_plot_boxplot_005.png :alt: Confidence intervals :srcset: /examples/dataset/images/sphx_glr_plot_boxplot_005.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 107-110 Plot horizontally ----------------- We can use horizontal bars: .. GENERATED FROM PYTHON SOURCE LINES 110-116 .. code-block:: default plot = Boxplot(dataset, use_vertical_bars=False) plot.title = "Horizontal bars" plot.execute(save=False, show=False) # Workaround for HTML rendering, instead of ``show=True`` plt.show() .. image-sg:: /examples/dataset/images/sphx_glr_plot_boxplot_006.png :alt: Horizontal bars :srcset: /examples/dataset/images/sphx_glr_plot_boxplot_006.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 117-120 Plot with other datasets ------------------------ We can add a dataset: .. GENERATED FROM PYTHON SOURCE LINES 120-125 .. code-block:: default plot = Boxplot(dataset, other_dataset) plot.title = "Additional dataset" plot.execute(save=False, show=False) # Workaround for HTML rendering, instead of ``show=True`` plt.show() .. image-sg:: /examples/dataset/images/sphx_glr_plot_boxplot_007.png :alt: Additional dataset :srcset: /examples/dataset/images/sphx_glr_plot_boxplot_007.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 1.035 seconds) .. _sphx_glr_download_examples_dataset_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 `_