# Group barchart with units#

This is the same example as the barchart in centimeters.

This example requires basic_units.py 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, labels=['G1', 'G2', 'G3', 'G4', 'G5'])

ax.legend()
ax.yaxis.set_units(inch)
ax.autoscale_view()

plt.show()


Keywords: matplotlib code example, codex, python plot, pyplot Gallery generated by Sphinx-Gallery
{"ft_lang_label":"__label__en","ft_lang_prob":0.54255974,"math_prob":0.96307844,"size":1009,"snap":"2022-40-2023-06","text_gpt3_token_len":343,"char_repetition_ratio":0.13631842,"word_repetition_ratio":0.0,"special_character_ratio":0.35282457,"punctuation_ratio":0.22807017,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98897773,"pos_list":[0,1,2],"im_url_duplicate_count":[null,1,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-02-04T05:25:30Z\",\"WARC-Record-ID\":\"<urn:uuid:f61e2d84-4bc7-4689-93e9-8207d5e1e5b9>\",\"Content-Length\":\"112547\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:bf3445aa-4fa7-412f-8937-d16860ef734d>\",\"WARC-Concurrent-To\":\"<urn:uuid:f8fef971-c5a9-4ac1-adcb-7fc8f6e034ed>\",\"WARC-IP-Address\":\"172.67.74.104\",\"WARC-Target-URI\":\"https://matplotlib.org/3.5.2/gallery/units/bar_unit_demo.html\",\"WARC-Payload-Digest\":\"sha1:7BIS34LLH54QUJRTKPRE6G6GCKDYUJJQ\",\"WARC-Block-Digest\":\"sha1:GBOF7KSOXFF7JVWWEETJYGRX6LEJFS4K\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-06/CC-MAIN-2023-06_segments_1674764500094.26_warc_CC-MAIN-20230204044030-20230204074030-00010.warc.gz\"}"}