.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/pie.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. or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_pie.py: ======= j. pie ======= .. currentmodule:: easy_mpl This file shows the usage of :func:`pie` function. .. GENERATED FROM PYTHON SOURCE LINES 9-20 .. code-block:: Python import numpy as np from easy_mpl import pie import matplotlib.pyplot as plt import matplotlib.colors as mcolors from easy_mpl.utils import version_info, map_array_to_cmap version_info() # sphinx_gallery_thumbnail_number = 5 .. rst-class:: sphx-glr-script-out .. code-block:: none {'easy_mpl': '0.21.5', 'matplotlib': '3.9.4', 'numpy': '2.0.2', 'pandas': '2.2.3', 'scipy': '1.13.1'} .. GENERATED FROM PYTHON SOURCE LINES 21-24 .. code-block:: Python _ = pie(np.random.randint(0, 3, 100)) .. image-sg:: /auto_examples/images/sphx_glr_pie_001.png :alt: pie :srcset: /auto_examples/images/sphx_glr_pie_001.png, /auto_examples/images/sphx_glr_pie_001_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 25-28 .. code-block:: Python _ = pie([0.2, 0.3, 0.1, 0.4]) .. image-sg:: /auto_examples/images/sphx_glr_pie_002.png :alt: pie :srcset: /auto_examples/images/sphx_glr_pie_002.png, /auto_examples/images/sphx_glr_pie_002_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 29-34 .. code-block:: Python # to explode 0.3 explode = (0, 0.1, 0, 0, 0) _ = pie(fractions=[0.2, 0.3, 0.15, 0.25, 0.1], explode=explode) .. image-sg:: /auto_examples/images/sphx_glr_pie_003.png :alt: pie :srcset: /auto_examples/images/sphx_glr_pie_003.png, /auto_examples/images/sphx_glr_pie_003_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 35-36 Specifying colors for each section of pie chart .. GENERATED FROM PYTHON SOURCE LINES 36-57 .. code-block:: Python rng = np.random.default_rng(313) labels = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct', 'Nov','Dec'] y = rng.integers(10, 100, 12) colors, _ = map_array_to_cmap(y, cmap="tab20") percent = 100.*y/y.sum() outs = pie(fractions=percent, autopct=None, colors=colors, show=False) patches, texts = outs labels = ['{0} - {1:1.2f} %'.format(i,j) for i,j in zip(labels, percent)] patches, labels, dummy = zip(*sorted(zip(patches, labels, y), key=lambda x: x[2], reverse=True)) plt.legend(patches, labels, bbox_to_anchor=(1.1, 1.), fontsize=8) plt.tight_layout() plt.show() .. image-sg:: /auto_examples/images/sphx_glr_pie_004.png :alt: pie :srcset: /auto_examples/images/sphx_glr_pie_004.png, /auto_examples/images/sphx_glr_pie_004_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 58-80 .. code-block:: Python seg_colors = ["#F5B800", "#4461A1", "#DF5F50"] # Change the saturation of seg_colors to 70% for the interior segments rgb = mcolors.to_rgba_array(seg_colors)[:,:-1] hsv = mcolors.rgb_to_hsv(rgb) hsv[:,1] = 0.7 * hsv[:, 1] interior_colors = mcolors.hsv_to_rgb(hsv) pie(fractions=[0.55, 0.2, 0.25], colors=seg_colors, labels=['Experimental', 'Physical', 'Synthesis'], wedgeprops=dict(edgecolor="w", width=0.03), radius=1, autopct=None, startangle=90, counterclock=False, show=False) pie(fractions=[0.55, 0.2, 0.25], colors=interior_colors, autopct='%1.0f%%', wedgeprops=dict(edgecolor="w"), radius=1-2*0.03, startangle=90, counterclock=False, ax=plt.gca(), show=False) plt.tight_layout() plt.show() .. image-sg:: /auto_examples/images/sphx_glr_pie_005.png :alt: pie :srcset: /auto_examples/images/sphx_glr_pie_005.png, /auto_examples/images/sphx_glr_pie_005_2_00x.png 2.00x :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.655 seconds) .. _sphx_glr_download_auto_examples_pie.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/sphinx-gallery/sphinx-gallery.github.io/master?urlpath=lab/tree/notebooks/auto_examples/pie.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: pie.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: pie.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: pie.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_