You are reading an old version of the documentation (v2.1.1). For the latest version see https://matplotlib.org/stable/gallery/lines_bars_and_markers/barh.html
matplotlib
Fork me on GitHub


Travis-CI:

Related Topics

This Page

Horizontal bar chartΒΆ

This example showcases a simple horizontal bar chart.

../../_images/sphx_glr_barh_001.png
import matplotlib.pyplot as plt
import numpy as np

# Fixing random state for reproducibility
np.random.seed(19680801)


plt.rcdefaults()
fig, ax = plt.subplots()

# Example data
people = ('Tom', 'Dick', 'Harry', 'Slim', 'Jim')
y_pos = np.arange(len(people))
performance = 3 + 10 * np.random.rand(len(people))
error = np.random.rand(len(people))

ax.barh(y_pos, performance, xerr=error, align='center',
        color='green', ecolor='black')
ax.set_yticks(y_pos)
ax.set_yticklabels(people)
ax.invert_yaxis()  # labels read top-to-bottom
ax.set_xlabel('Performance')
ax.set_title('How fast do you want to go today?')

plt.show()

Total running time of the script: ( 0 minutes 0.022 seconds)

Gallery generated by Sphinx-Gallery