How to create a BarPlot in SeaBorn?

Let’s learn on how to create a BarPlot in SeaBorn Python library.

Data preparation

I have prepared csv file with registration vehicles data.

Let’s see the details using Pandas Python library.

import pandas as pd

cars = pd.read_csv('vehicles.csv')
print(cars)

vehicles registartion data

A bar graph preparation

I’d like to create a barplot chart which contains the data about the number of registered vehicles.

See also  How to generate distribution plot the easiest way in Python?

I need to see Body_Type and No_Of_Vehicles.

To create a basic SeaBorn BarPlot I need to import Pandas, Seaborn and Matplotlib Python libraries. To insert a barplot I am using seaborn.barplot method. As x and y I’m taking the columns I need. And data is my data source which I defined. Plt.show function will help to display the chart.

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sn

cars = pd.read_csv('vehicles.csv')

sn.barplot(x = 'Body_Type', y = 'No_Of_Vehicles',
           data = cars)
plt.show()

Seaborn barplot