.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plotting/_violin.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plotting__violin.py: ============== 6.17 violin ============== .. currentmodule:: easy_mpl This file shows the usage of :func:`violin_plot` function. .. GENERATED FROM PYTHON SOURCE LINES 9-19 .. code-block:: default import numpy as np import pandas as pd import matplotlib.pyplot as plt from easy_mpl import violin_plot from easy_mpl.utils import _rescale from easy_mpl.utils import version_info version_info() .. rst-class:: sphx-glr-script-out .. code-block:: none {'easy_mpl': '0.21.4', 'matplotlib': '3.8.4', 'numpy': '1.26.4', 'pandas': '1.5.3', 'scipy': '1.13.1'} .. GENERATED FROM PYTHON SOURCE LINES 20-27 .. code-block:: default f = "https://raw.githubusercontent.com/AtrCheema/AI4Water/master/ai4water/datasets/arg_busan.csv" df = pd.read_csv(f, index_col='index') cols = ['air_temp_c', 'wat_temp_c', 'sal_psu', 'tide_cm', 'rel_hum', 'pcp12_mm'] for col in df.columns: df[col] = _rescale(df[col].values) .. GENERATED FROM PYTHON SOURCE LINES 28-29 The basic violin plot can be drawn by passing a pandas DataFrame with one or more columns. .. GENERATED FROM PYTHON SOURCE LINES 29-32 .. code-block:: default _ = violin_plot(df[cols]) .. image-sg:: /auto_examples/plotting/images/sphx_glr__violin_001.png :alt: violin :srcset: /auto_examples/plotting/images/sphx_glr__violin_001.png, /auto_examples/plotting/images/sphx_glr__violin_001_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 33-35 The function `:func:`violin_plot` always returns a matplotlib axes object. If we set ``show`` to False then, the returned axes can be used for further manipulation. .. GENERATED FROM PYTHON SOURCE LINES 35-40 .. code-block:: default axes = violin_plot(df[cols], show=False) axes.set_facecolor("#fbf9f4") plt.show() .. image-sg:: /auto_examples/plotting/images/sphx_glr__violin_002.png :alt: violin :srcset: /auto_examples/plotting/images/sphx_glr__violin_002.png, /auto_examples/plotting/images/sphx_glr__violin_002_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 41-42 The value of ``cut`` determines the length of tails on both sides. .. GENERATED FROM PYTHON SOURCE LINES 42-46 .. code-block:: default axes = violin_plot(df[cols], show=False, cut=0.1) axes.set_facecolor("#fbf9f4") plt.show() .. image-sg:: /auto_examples/plotting/images/sphx_glr__violin_003.png :alt: violin :srcset: /auto_examples/plotting/images/sphx_glr__violin_003.png, /auto_examples/plotting/images/sphx_glr__violin_003_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 47-49 We can specify colors for each of the violin plot separately. It can be any valid matplotlib colors i.e., name of color as string or its RGB vlaue. .. GENERATED FROM PYTHON SOURCE LINES 49-62 .. code-block:: default axes = violin_plot( df[cols], show=False, cut=0.1, fill=False, scatter_kws={"s": 12, 'alpha': 0.5, 'edgecolors': None, 'linewidths': 0.2}, datapoints_colors=['seagreen', np.array([237, 187, 147]) / 255, np.array([197, 194, 218]) / 255, 'darkcyan', 'skyblue', "plum", ] ) axes.set_facecolor("#fbf9f4") plt.show() .. image-sg:: /auto_examples/plotting/images/sphx_glr__violin_004.png :alt: violin :srcset: /auto_examples/plotting/images/sphx_glr__violin_004.png, /auto_examples/plotting/images/sphx_glr__violin_004_2_0x.png 2.0x :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 1.468 seconds) .. _sphx_glr_download_auto_examples_plotting__violin.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/AtrCheema/python-seekho/master?urlpath=lab/tree/notebooks/auto_examples/plotting/_violin.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: _violin.py <_violin.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: _violin.ipynb <_violin.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_