.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/spread/ex_spread.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_spread_ex_spread.py: ==================== spread example ==================== .. GENERATED FROM PYTHON SOURCE LINES 7-53 .. image-sg:: /examples/spread/images/sphx_glr_ex_spread_001.png :alt: ex spread :srcset: /examples/spread/images/sphx_glr_ex_spread_001.png :class: sphx-glr-single-img .. code-block:: Python import pandas as pd import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl import seaborn as sns # Create the data : copied from examples/kde_ridgeplot.py rs = np.random.RandomState(1979) x = rs.randn(500) g = np.tile(list("ABCDEFGHIJ"), 50) df = pd.DataFrame(dict(x=x, g=g)) m = df.g.map(ord) df["x"] += m fig, ax = plt.subplots(1, 1, num=1, clear=True) sns.kdeplot( df, x="x", hue="g", ax=ax, fill=True, linewidth=2, clip_on=False, ec="w", alpha=1, ) from mpl_visual_context.spreader import spready polys = ax.collections dy = 0.5 * max([p.get_datalim(p.axes.transData).height for p in polys]) yindices = np.arange(len(polys)) gg = df["g"].unique() yoffsets = spready(polys, yindices, dy=dy) ax.set_ylim(min(yoffsets), max(yoffsets) + dy) ax.set_yticks(yoffsets, labels=gg[::-1]) ax.legend_.remove() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.126 seconds) .. _sphx_glr_download_examples_spread_ex_spread.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ex_spread.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ex_spread.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: ex_spread.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_