.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/statistical_plots/box_vs_violin.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_statistical_plots_box_vs_violin.py: Box vs Violin ============= Compare distribution shape with a classic box-and-whisker vs. violin plot. .. GENERATED FROM PYTHON SOURCE LINES 7-48 .. image-sg:: /examples/statistical_plots/images/sphx_glr_box_vs_violin_001.png :alt: Box-and-Whisker, Violin :srcset: /examples/statistical_plots/images/sphx_glr_box_vs_violin_001.png :class: sphx-glr-single-img .. code-block:: Python import numpy as np import matplotlib.pyplot as plt from emcpy.plots.plots import BoxandWhiskerPlot, ViolinPlot from emcpy.plots.create_plots import CreatePlot, CreateFigure rng = np.random.default_rng(0) g1 = rng.normal(0.0, 1.0, 400) g2 = rng.normal(1.0, 0.6, 400) g3 = rng.normal(-0.5, 0.8, 400) groups = [g1, g2, g3] labels = ["Group A", "Group B", "Group C"] # Left: box-and-whisker p_left = CreatePlot() bp = BoxandWhiskerPlot(groups) bp.tick_labels = labels bp.patch_artist = True # filled boxes p_left.plot_layers = [bp] p_left.add_title("Box-and-Whisker") p_left.add_ylabel("value") p_left.add_grid() # Right: violin p_right = CreatePlot() vp = ViolinPlot(groups) vp.showmedians = True p_right.plot_layers = [vp] p_right.add_title("Violin") p_right.add_ylabel("value") p_right.add_grid() # Keep x tick labels consistent p_right.set_xticks([1, 2, 3]) p_right.set_xticklabels(labels) fig = CreateFigure(nrows=1, ncols=2, figsize=(10, 4)) fig.plot_list = [p_left, p_right] fig.create_figure() fig.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.131 seconds) .. _sphx_glr_download_examples_statistical_plots_box_vs_violin.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: box_vs_violin.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: box_vs_violin.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: box_vs_violin.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_