.. 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-36 .. code-block:: default from __future__ import annotations from gemseo import configure_logger from gemseo.datasets.io_dataset import IODataset 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-49 .. code-block:: default 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 50-53 Plot y1 and y2 -------------- We can use the :class:`.Boxplot` plot. .. GENERATED FROM PYTHON SOURCE LINES 53-59 .. 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 60-63 Plot with centering ------------------- We can center the data: .. GENERATED FROM PYTHON SOURCE LINES 63-67 .. 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 68-71 Plot with scaling ----------------- We can scale the data (normalization with the standard deviation): .. GENERATED FROM PYTHON SOURCE LINES 71-75 .. 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 76-79 Plot without outliers --------------------- We can remove the outliers: .. GENERATED FROM PYTHON SOURCE LINES 79-83 .. 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 84-87 Plot with confidence intervals ------------------------------ We can add confidence intervals for the median: .. GENERATED FROM PYTHON SOURCE LINES 87-91 .. 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 92-95 Plot horizontally ----------------- We can use horizontal bars: .. GENERATED FROM PYTHON SOURCE LINES 95-99 .. 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 100-103 Plot with other datasets ------------------------ We can add a dataset: .. GENERATED FROM PYTHON SOURCE LINES 103-106 .. 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 1.112 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 `_