Plotting graph using seaborn in python.



Seaborn is a Python visualization library built on top of matplotlib. It provides the interface for drawing statistical graphics. It simplifies the process of creating complex visualizations such as histograms, bar plots, etc.

In this article, we are going to learn how to plot a graph using Seaborn in Python. To use Seaborn, we need to install it by using the command below.

pip install seaborn

Now, import the required libraries:

import seaborn as sns import matplotlib.pyplot as plt

Using seaborn.lineplot() Method

The seaborn.lineplot() method is used to draw a line plot with the possibility of several semantic groupings. Following is the syntax of Python seaborn.lineplot() method -

seaborn.lineplot(x=None, y=None,)

In this approach, we are going to declare the dataset and apply the lineplot() method for drawing the line containing the data points.

Example

Let's look at the following example, where we are going to create a line plot to visualize how the number of sales increased over the years.

import seaborn as sns import matplotlib.pyplot as plt import pandas as pd car = pd.DataFrame({ 'year': [2015, 2016, 2017, 2018, 2019, 2020], 'sales': [100, 150, 200, 180, 220, 170] }) sns.lineplot(x='year', y='sales', data=car) plt.title("Yearly Sales Count") plt.show()

The output of the above program is as follows -


Using sns.scatterplot() Method

The sns.scatterplot() method is a part of the seaborn library used to create scatter plots, a type of data visualization that shows the relationship between two continuous variables.

Syntax

Following is the syntax of the Python sns.scatterplot() method -

seaborn.lineplot(x=None, y=None,)

Example

Consider the following example, where we are going to use the sns.scatterplot() and plot the graph.

import seaborn as sns import matplotlib.pyplot as plt import pandas as pd users = pd.DataFrame({ 'airtel': [25,40,45,55,15], 'idea': [20,45,50,60,10] }) sns.scatterplot(x='airtel', y='idea', data=users) plt.title("Network Users") plt.xlabel("Airtel Users") plt.ylabel("Idea Users") plt.show()

The output of the above program is as follows -


Using sns.barplot() Method

The sns.barplot() method is a part of the seaborn library that is used to create bar plots. It is commonly used for visualizing the relationship between a categorical variable and a continuous variable. Following is the syntax of the Python sns.barplot() method -

seaborn.lineplot(x=None, y=None,)

Example

Consider the following example, where we are going to use the sns.scatterplot() and plot the graph.

import seaborn as sns import matplotlib.pyplot as plt import pandas as pd cars = pd.DataFrame({ 'cars': ['Cheron', 'BMW', 'Audi'], 'sales': [130, 100, 150] }) sns.barplot(x='cars', y='sales', data=cars) plt.title("Average sales of car") plt.show()

The output of the above program is as follows -


Updated on: 2025-06-17T17:31:26+05:30

703 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements