Create a horizontal bar plot in Matplotlib

Python

Matplotlib

Bar

Create horizontal

Luc B.

Python

Matplotlib

Bar Plot

Bar charts are important tools for creating comparative visualizations of discrete data. Matplotlib makes it easy to create these powerful plots.

Code Example

Use the plt.barh() function to create a horizontal bar plot in Matplotlib.

import matplotlib.pyplot as plt

labels = ['Amy', 'Rob', 'Dimitri', 'Sarah', 'Brian']
values = [60, 56, 63, 75, 48]

# Create horizontal bar plot here
plt.barh(labels, values)

plt.ylabel('Typing Speed (wpm)')
plt.show()

png

To create a vertical bar plot, take a look at this article.