.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_stacked_bar.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_auto_examples_plot_stacked_bar.py: Annotate stacked bar ==================== .. GENERATED FROM PYTHON SOURCE LINES 6-30 .. image-sg:: /auto_examples/images/sphx_glr_plot_stacked_bar_001.png :alt: plot stacked bar :srcset: /auto_examples/images/sphx_glr_plot_stacked_bar_001.png, /auto_examples/images/sphx_glr_plot_stacked_bar_001_2_00x.png 2.00x :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import pandas as pd import marsilea as ma import marsilea.plotter as mp np.random.seed(0) data = np.random.randint(1, 100, (5, 10)) data = pd.DataFrame(data=data, index=list("abcde")) bar = mp.StackBar(data / data.sum(), width=.9, legend_kws=dict(title="Stacked Bar")) top_colors = mp.Colors([1, 1, 2, 2, 4], cmap="Set2", label="Category") top_mesh = mp.ColorMesh(data.sum(), cmap="cool", label="Total", cbar_kws=dict(orientation="horizontal")) wb = ma.WhiteBoard(width=3, height=3, margin=.2) wb.add_layer(bar) wb.add_top(top_colors, size=.2) wb.add_top(top_mesh, size=.2, pad=.1) wb.add_legends() wb.set_margin(.2) wb.render() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.003 seconds) .. _sphx_glr_download_auto_examples_plot_stacked_bar.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_stacked_bar.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_stacked_bar.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_