.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/demo_nested_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 .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_demo_nested_pie.py: ==================== Nested pie chart ==================== .. GENERATED FROM PYTHON SOURCE LINES 6-73 .. image-sg:: /examples/images/sphx_glr_demo_nested_pie_001.png :alt: Nested Pie plot with 3d effects :srcset: /examples/images/sphx_glr_demo_nested_pie_001.png :class: sphx-glr-single-img .. code-block:: Python import numpy as np import matplotlib.pyplot as plt fig, ax = plt.subplots(num=1, clear=True) size = 0.3 vals = np.array([[60., 32.], [37., 40.], [29., 10.]]) cmap = plt.colormaps["tab20c"] outer_colors = cmap(np.arange(3)*4) inner_colors = cmap([1, 2, 5, 6, 9, 10]) wedges1, _ = ax.pie(vals.sum(axis=1), radius=1, colors=outer_colors, wedgeprops=dict(width=size, edgecolor='w')) wedges2, _ = ax.pie(vals.flatten(), radius=0.95-size, colors=inner_colors, wedgeprops=dict(width=size, edgecolor='w')) ax.set(aspect=0.6, title='Nested Pie plot with 3d effects') # 3d effects from matplotlib.colors import LightSource from mpl_poormans_3d import Poormans3d, Poormans3dFace from mpl_poormans_3d.poormans_3d import ArtistListWithPoormans3d ls = LightSource(azdeg=35) # We add 3d effects using ArtistListWithPoormans3d and Poomans3dFace. See # demo_pie.py. patch_list = wedges1 + wedges2 height = np.array([0, -40]) kw = dict(fraction=0.3, direction=1) kw_face = dict(fraction=0.3) al = ArtistListWithPoormans3d(patch_list, ls, 0.5* height, displacement0=0, **kw) ax.add_artist(al) for patch in patch_list: patch.set_path_effects([ Poormans3dFace(ls, 0, **kw_face), ]) # For the inner wedges, We add another depth patch_list = wedges2 height = np.array([0, 40]) kw = dict(fraction=0.3, direction=-1) kw_face = dict(fraction=0.3) al = ArtistListWithPoormans3d(patch_list, ls, 0.5* height, displacement0=0, **kw) al.set_zorder(1.2) ax.add_artist(al) for patch in patch_list: patch.set_path_effects([ Poormans3dFace(ls, 0.5*height, **kw_face), ]) patch.set_zorder(1.3) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.210 seconds) .. _sphx_glr_download_examples_demo_nested_pie.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_nested_pie.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_nested_pie.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_