How to Create a Bar Plot with Matplotlib

2020-12-16

Intro

Bar plots are a fundamental plot in data analysis. The help you view the distribution (count) of different categories. When you have a categorical variable such as month, it is a good idea to view the distribution.

Let's say we have sales of books grouped by month. The month is our categorical variable, and we want to view the count of each month (the number of books sold that month).

Creating a Bar Plot

import matplotlib.pyplot as plt

month = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
books = [
          5000, 4300, 8590, 9000,
          9100, 7050, 8000, 8500,
          8000, 7000, 9590, 8500
        ]


plt.bar(month, books)
plt.show()
GoTea - KoalaTea