.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/units/bar_unit_demo.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. meta:: :keywords: codex .. 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_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 ` .. GENERATED FROM PYTHON SOURCE LINES 14-43 .. image-sg:: /gallery/units/images/sphx_glr_bar_unit_demo_001.png :alt: Cup height by group and beverage choice :srcset: /gallery/units/images/sphx_glr_bar_unit_demo_001.png, /gallery/units/images/sphx_glr_bar_unit_demo_001_2_00x.png 2.00x :class: sphx-glr-single-img .. code-block:: Python from basic_units import cm, inch import matplotlib.pyplot as plt import numpy as np N = 5 tea_means = [15*cm, 10*cm, 8*cm, 12*cm, 5*cm] tea_std = [2*cm, 1*cm, 1*cm, 4*cm, 2*cm] fig, ax = plt.subplots() ax.yaxis.set_units(inch) ind = np.arange(N) # the x locations for the groups width = 0.35 # the width of the bars ax.bar(ind, tea_means, width, bottom=0*cm, yerr=tea_std, label='Tea') coffee_means = (14*cm, 19*cm, 7*cm, 5*cm, 10*cm) coffee_std = (3*cm, 5*cm, 2*cm, 1*cm, 2*cm) ax.bar(ind + width, coffee_means, width, bottom=0*cm, yerr=coffee_std, label='Coffee') ax.set_title('Cup height by group and beverage choice') ax.set_xticks(ind + width / 2, labels=['G1', 'G2', 'G3', 'G4', 'G5']) ax.legend() ax.autoscale_view() plt.show() .. _sphx_glr_download_gallery_units_bar_unit_demo.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: bar_unit_demo.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: bar_unit_demo.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_