.. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_units_bar_unit_demo.py: ========================= Group barchart with units ========================= This is the same example as :doc:`the barchart` in centimeters. .. only:: builder_html This example requires :download:`basic_units.py ` .. image:: /gallery/units/images/sphx_glr_bar_unit_demo_001.png :alt: Scores by group and gender :class: sphx-glr-single-img .. code-block:: default import numpy as np from basic_units import cm, inch import matplotlib.pyplot as plt N = 5 men_means = [150*cm, 160*cm, 146*cm, 172*cm, 155*cm] men_std = [20*cm, 30*cm, 32*cm, 10*cm, 20*cm] fig, ax = plt.subplots() ind = np.arange(N) # the x locations for the groups width = 0.35 # the width of the bars ax.bar(ind, men_means, width, bottom=0*cm, yerr=men_std, label='Men') women_means = (145*cm, 149*cm, 172*cm, 165*cm, 200*cm) women_std = (30*cm, 25*cm, 20*cm, 31*cm, 22*cm) ax.bar(ind + width, women_means, width, bottom=0*cm, yerr=women_std, label='Women') ax.set_title('Scores by group and gender') ax.set_xticks(ind + width / 2) ax.set_xticklabels(('G1', 'G2', 'G3', 'G4', 'G5')) ax.legend() ax.yaxis.set_units(inch) ax.autoscale_view() plt.show() .. _sphx_glr_download_gallery_units_bar_unit_demo.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: bar_unit_demo.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: bar_unit_demo.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature Keywords: matplotlib code example, codex, python plot, pyplot `Gallery generated by Sphinx-Gallery `_