Skip to main content

Seaborn: Scatter plot

A scatterplot is used when there is a possibility of several semantic groupings. It can plot 2-D graph whose mapping can be enhanced by using some additional variables like hue, size and style parameters. These parameters are used to control visual semantics which can identify the different subsets.

Syntax

seaborn.scatterplot(x=None, y=None, hue=None, style=None, size=None, data=None, 
palette=None, hue_order=None, hue_norm=None, sizes=None, size_order=None, size_norm=None, 
markers=True, style_order=None, x_bins=None, y_bins=None, units=None, estimator=None, ci=95, 
n_boot=1000, alpha=’auto’, x_jitter=None, y_jitter=None, legend=’brief’, ax=None, **kwargs)

Examples

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns


data=sns.load_dataset('iris')
data.shape

Output:

(150, 5)
#simple scatterplot
sns.scatterplot(y='sepal_length',x='sepal_width',data=data)

Output:

scatter

#using hue
sns.scatterplot(y='sepal_length',x='sepal_width',hue='species',data=data)

Output:

scatter hue

#styling
sns.scatterplot(x='sepal_width', y='sepal_length', hue='species', style='species',
data=data, s=100)

Output:

hue

plt.figure(figsize=(10,8))
sns.scatterplot(x='sepal_width', y='sepal_length', hue='species',data=data,s=200, 
marker='*',edgecolor='black')

Output:

fig size

Submitted by devanshi.srivastava on December 28, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.