.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/demo_stacked.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_stacked.py: ==================== Labeled Stacked Barchart ==================== .. GENERATED FROM PYTHON SOURCE LINES 6-61 .. image-sg:: /examples/images/sphx_glr_demo_stacked_001.png :alt: demo stacked :srcset: /examples/images/sphx_glr_demo_stacked_001.png :class: sphx-glr-single-img .. code-block:: Python import numpy as np import matplotlib import matplotlib.pyplot as plt np.random.seed(16) x = ["a","b","c","d"] yy = np.random.random((5, len(x))) yy = yy / yy.sum(axis=0) * 100 fig, ax = plt.subplots(num=1, clear=True) bottom = np.zeros_like(yy[0]) for y in yy: ax.bar(x, y, bottom=bottom) bottom += y from matplotlib.colors import LightSource from mpl_poormans_3d import BarToPrism, BarToCylinder from mpl_poormans_3d import Poormans3d, Poormans3dFace from mpl_visual_context.patheffects import (Offset, Affine, ClipPathSelf, GCModify, StrokeOnly, StrokeColorFromFillColor, HLSModify) ax.set_ylim(-7, 140) ls = LightSource(azdeg=40) # ls2 = LightSource(azdeg=180+20) # bar_to_prism = BarToPrism(ls, 4, ratio=0.3, rotate_deg=10) bar_to_prism = BarToCylinder(ls, ratio=0.3) for i, container in enumerate(ax.containers): offset = Offset(0, i*10) for p in container.patches: p.set_path_effects([offset | bar_to_prism]) pe_engraved = ClipPathSelf() | Poormans3d(ls, (0, -2)) pe3d_face = Poormans3dFace(ls, (0, 0)) for i, c in enumerate(x): t = ax.text(i, 100, c, ha="center", va="baseline", size=60, color=ax.containers[-1].patches[0].get_fc()) scale = Affine().translate(0, 15).scale(1, 0.3).translate(0, -15) t.set_path_effects([ scale | offset, scale | offset | pe_engraved, scale | offset | pe3d_face | StrokeColorFromFillColor() | StrokeOnly() ]) ax.set_yticks([]) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.350 seconds) .. _sphx_glr_download_examples_demo_stacked.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_stacked.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_stacked.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_