.. 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 :ref:`Go to the end ` 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-38 .. code-block:: Python from __future__ import annotations from numpy import hstack from numpy import linspace from gemseo import configure_logger from gemseo.datasets.io_dataset import IODataset from gemseo.post.dataset.boxplot import Boxplot configure_logger() .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 39-41 Build a dataset --------------- .. GENERATED FROM PYTHON SOURCE LINES 41-51 .. code-block:: Python inputs = linspace(-1, 1, 100)[:, None] dataset = IODataset(dataset_name="Foo") dataset.add_output_variable("y1", inputs**2) dataset.add_output_variable("y2", hstack((inputs**3, inputs**4))) other_dataset = IODataset(dataset_name="Bar") other_dataset.add_output_variable("y1", -(inputs**2)) other_dataset.add_output_variable("y2", hstack((-(inputs**3), -(inputs**4)))) .. GENERATED FROM PYTHON SOURCE LINES 52-55 Plot y1 and y2 -------------- We can use the :class:`.Boxplot` plot. .. GENERATED FROM PYTHON SOURCE LINES 55-61 .. code-block:: Python 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 62-65 Plot with centering ------------------- We can center the data: .. GENERATED FROM PYTHON SOURCE LINES 65-69 .. code-block:: Python 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 70-73 Plot with scaling ----------------- We can scale the data (normalization with the standard deviation): .. GENERATED FROM PYTHON SOURCE LINES 73-77 .. code-block:: Python 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 78-81 Plot without outliers --------------------- We can remove the outliers: .. GENERATED FROM PYTHON SOURCE LINES 81-85 .. code-block:: Python 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 86-89 Plot with confidence intervals ------------------------------ We can add confidence intervals for the median: .. GENERATED FROM PYTHON SOURCE LINES 89-93 .. code-block:: Python 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 94-97 Plot horizontally ----------------- We can use horizontal bars: .. GENERATED FROM PYTHON SOURCE LINES 97-101 .. code-block:: Python 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 102-105 Plot with other datasets ------------------------ We can add a dataset: .. GENERATED FROM PYTHON SOURCE LINES 105-108 .. code-block:: Python 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 1.063 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-jupyter :download:`Download Jupyter notebook: plot_boxplot.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_boxplot.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_