Getting Started with Seaborn: Install, Import, and Usage

Getting Started with Seaborn: Install, Import, and Usage

Seaborn Library in Python

Seaborn is a visualization library for plotting good-looking and stylish graphs in Python. It provides different types of styles and color themes to make good-looking graphs. The latest version of the seaborn library is 0.11.2.

Installation

pip install seaborn

Mandatory dependencies

Importing Seaborn Library

import seaborn as sb

Using Seaborn Library for Creating Graphs

Creating Line Graph

# Importing Seaborn and Matplotlib Library For Graph Plotting
import seaborn as sb
import matplotlib.pyplot as plt

# Setting theme of our Graph using set_theme() function
sb.set_theme(style="darkgrid")

# Creating a List of Data for Graph Plotting
graph_data = [1, 750, 250, 2400, 2000]

# Plotting a Line Graph Using Seaborn Library
sb.lineplot(data = graph_data)

# Showing the plotted graph using show() function of matplolib library
plt.show()

Output:

Output for Creating Line Graph using Seaborn Library in Python
Output for Creating Line Graph using Seaborn Library in Python

Creating Scattered Line Graph

# Importing Seaborn Matplotlib and Numpy Library For Graph Plotting
import seaborn as sb
import matplotlib.pyplot as plt
import numpy as np

# Randomising the data to get random x and y co-ordinates for plotting
rs = np.random.RandomState(7)
x = rs.normal(2, 1, 75)
y = 2 + 1.5 * x + rs.normal(0, 2, 75)

# Plotting x and y co-ordinates using residpolt() function
sb.residplot(x=x, y=y)

# Showing the plotted graph using show() function of matplolib library
plt.show()

Output:

Output for Creating Scattered Line Graph using Seaborn Library in Python
Output for Creating Scattered Line Graph using Seaborn Library in Python

Creating BoxPlot Graphs

# Importing Seaborn and Matplotlib Library For Graph Plotting
import seaborn as sb
import matplotlib.pyplot as plt

# Setting the style of our Graph using set() function
sb.set_theme(style="whitegrid")

# Using load_datatset() function to get data for graph plotting
example = sb.load_dataset("tips")

# Plotting a Line Graph Using Seaborn Library
sb.boxplot(x="day", y="total_bill",
            hue="smoker", palette=["m", "g"],
            data=example)
sb.despine(offset=10, trim=True)

# Showing the plotted graph using show() function of matplolib library
plt.show()

Output:

Output for Creating BoxPlot Graphs using Seaborn Library in Python
Output for Creating BoxPlot Graphs using Seaborn Library in Python

We hope this article on Graph Plotting using Seaborn Library in Python helps you.

Thank you for reading this article, click here to start learning Python in 2022.


Also Read:

Share:

Author: Aviral Kaushik

My Official Website = aviralkaushik.epizy.com Skills for Website Development : HTML, CSS, JavaScript, PHP, Angular, React, Node JS, Vue JS and Python (Django). Skills for Android Development : Android Development using Android Studio, Kotlin , Java, Flutter, Electron JS, React Native, KVM and Kivy. Skills for Software Development : Python (TKinter + Pyqt5), Java (Swing + Java Fx), C, C++, C# using ASP.NET, Electron JS and Ionic JS. Skills for IoS Development : React Native, Flutter, Kotlin, KVM and Swift