Matplotlib – Bar Plot

To draw a Bar Plot using Matplotlib, call function, and pass required values (X-axis, and bar heights) for the bar plot.

The definition of function is

bar(x, height, width=0.8, bottom=None, *, align='center', data=None, **kwargs):


In the following program, we will take some sample data for X-axis and height of the bars to draw a bar plot.

The data for X-axis of bar plot is [1, 2, 3, 4, 5].

The data for height of the bars (Y-axis) in the plot is [10, 8, 12, 4, 7].

import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]
h = [10, 8, 12, 4, 7]

#bar plot, height = h)


Matplotlib - Bar Plot


In this Matplotlib Tutorial, we learned how to draw a bar plot using Matplotlib PyPlot API.