Barplot

A barplot shows the relationship between a numeric and a categoric variable. Each entity of the categoric variable is represented as a bar. The size of the bar represents its numeric value.
This section shows how to build a barplot with Python, using libraries like Matplotlib and Seaborn. It start by explaining how to build a very basic barplot, and then provides tutorials for more customized versions.
Note that this page also provides guidelines on how to build stacked and grouped barplot, 2 common variatons useful when several levels of grouping are available.
⏱ Quick start
Matplotlib is pretty convenient to build a barplot thanks to its bar() function. Seaborn works perfectly as well, see its dedicated section.🔥
# Libraries
import numpy as np
import matplotlib.pyplot as plt
# Make a random dataset:
height = [3, 12, 5, 18, 45]
bars = ('A', 'B', 'C', 'D', 'E')
y_pos = np.arange(len(bars))
# Create bars
plt.bar(y_pos, height)
# Create names on the x-axis
plt.xticks(y_pos, bars)
# Show graphic
plt.show()
Barplot with Matplotlib
Matplotlib is probably the most famous and flexible python library for data visualization. It is appropriate to build any kind of chart, including the barchart thanks to its bar() function.
The examples below should get you started. They go from basic examples to the details on how to customize a barplot appropriately.



