0% found this document useful (0 votes)
13 views100 pages

Numpy 3

The document provides a comprehensive guide on creating violin plots and strip plots using the Seaborn library in Python. It includes syntax, parameters, and multiple examples for visualizing data from datasets such as 'fmri' and 'tips'. The document emphasizes the customization options available for enhancing the visual appeal of the plots.

Uploaded by

virajsawant0293
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views100 pages

Numpy 3

The document provides a comprehensive guide on creating violin plots and strip plots using the Seaborn library in Python. It includes syntax, parameters, and multiple examples for visualizing data from datasets such as 'fmri' and 'tips'. The document emphasizes the customization options available for enhancing the visual appeal of the plots.

Uploaded by

virajsawant0293
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Search...

Tutorials
Practice V
Jobs
Python Tutorial Data Types Interview Questions Examples Quizzes DSA Python Data Science NumPy Pandas Practice

Violinplot using Seaborn in Python


Last Updated : 15 Jul, 2025

Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides
beautiful default styles and color palettes to make statistical plots more attractive. It is built on the
top of matplotlib library and also closely integrated into the data structures from pandas.
Violin Plot
A violin plot plays a similar activity that is pursued through whisker or box plot do. As it shows
several quantitative data across one or more categorical variables. It can be an effective and
attractive way to show multiple data at several units. A “wide-form” Data Frame helps to maintain
each numeric column which can be plotted on the graph. It is possible to use NumPy or Python
objects, but pandas objects are preferable because the associated names will be used to annotate
the axes.

Syntax: [Link](x=None, y=None, hue=None, data=None, order=None,


hue_order=None, bw='scott', cut=2, scale='area', scale_hue=True, gridsize=100, width=0.8,
inner='box', split=False, dodge=True, orient=None, linewidth=None, color=None, palette=None,
saturation=0.75, ax=None, **kwargs)
Parameters:
x, y, hue: Inputs for plotting long-form data.
data: Dataset for plotting.
scale: The method used to scale the width of each violin.

Returns: This method returns the Axes object with the plot drawn onto it.
Example 1: Basic visualization of “fmri” dataset using violinplot()

import seaborn

[Link](style = 'whitegrid')
fmri = seaborn.load_dataset("fmri")

[Link](x ="timepoint",
y ="signal",
data = fmri)

Output:
Example 2: Grouping data points on the basis of category, here as region and event.

import seaborn

[Link](style = 'whitegrid')
fmri = seaborn.load_dataset("fmri")

[Link](x ="timepoint",
y ="signal",
hue ="region",
style ="event",
data = fmri)

Output:

Example 3: Basic visualization of “tips” dataset using lineplot()

import seaborn

[Link](style = 'whitegrid')
tip = seaborn.load_dataset('tips')

[Link](x ='day', y ='tip', data = tip)

Output:
Grouping variables in Seaborn violinplot with different attributes:
[Link] a single horizontal swarm plot using only one axis:
If we use only one data variable instead of two data variables then it means that the axis denotes
each of these data variables as an axis.
X denotes an x-axis and y denote a y-axis.
Syntax:

[Link](x)

Code:

# Python program to illustrate


# violinplot using inbuilt data-set
# given in seaborn

# importing the required module


import seaborn

# use to set style of background of plot


[Link](style="whitegrid")

# loading data-set
tips = seaborn.load_dataset("tips")

[Link](x=tip["total_bill"])

Output:

2. Draw horizontal violinplot:


In the above example we see how to plot a single horizontal violinplot plot and here can perform
multiple horizontal plot with exchange the data variable with another axis.

# Python program to illustrate


# violinplot using inbuilt data-set
# given in seaborn

# importing the required module


import seaborn

# use to set style of background of plot


[Link](style="whitegrid")

# loading data-set
tips = seaborn.load_dataset("tips")

[Link](x="tip", y="day", data=tip)

Output:

3. Using hue parameter:


While the points are plotted in two dimensions, another dimension can be added to the plot by
coloring the points according to a third variable.
Syntax:

[Link](x, y, hue, data)

# Python program to illustrate


# violinplot using inbuilt data-set
# given in seaborn

# importing the required module


import seaborn

# use to set style of background of plot


[Link](style="whitegrid")

# loading data-set
tips = seaborn.load_dataset("tips")

[Link](x="day", y="total_bill", hue="time", data=tips)

Output:
4. Draw outlines around the data points using linewidth:
Width of the gray lines that frame the plot elements. Whenever we increase linewidth than the point
also will increase automatically.
Syntax:

[Link](x, y, data, linewidth)

# Python program to illustrate


# violinplot using inbuilt data-set
# given in seaborn

# importing the required module


import seaborn

# use to set style of background of plot


[Link](style="whitegrid")

# loading data-set
tips = seaborn.load_dataset("tips")

[Link](x ='day', y ='tip', data = tip, linewidth = 4)

Output:

5. Draw each level of the hue variable at different locations on the major categorical axis:
When using hue nesting, setting dodge should be True will separate the point for different hue levels
along the categorical axis. And Palette is used for the different levels of the hue variable.
Syntax:

[Link](x, y, data, hue, palette, dodge)

# Python program to illustrate


# violinplot using inbuilt data-set
# given in seaborn

# importing the required module


import seaborn

# use to set style of background of plot


[Link](style="whitegrid")

# loading data-set
tips = seaborn.load_dataset("tips")

[Link](x="day", y="total_bill", hue="smoker",


data=tips, palette="Set2", dodge=True)

Output:

Possible values of palette are:

Accent, Accent_r, Blues, Blues_r, BrBG, BrBG_r, BuGn, BuGn_r, BuPu, BuPu_r, CMRmap,
CMRmap_r, Dark2, Dark2_r,

GnBu, GnBu_r, Greens, Greens_r, Greys, Greys_r, OrRd, OrRd_r, Oranges, Oranges_r, PRGn,
PRGn_r, Paired, Paired_r,

Pastel1, Pastel1_r, Pastel2, Pastel2_r, PiYG, PiYG_r, PuBu, PuBuGn, PuBuGn_r, PuBu_r, PuOr,
PuOr_r, PuRd, PuRd_r,

Purples, Purples_r, RdBu, RdBu_r, RdGy, RdGy_r, RdPu, RdPu_r, RdYlBu, RdYlBu_r, RdYlGn,
RdYlGn_r, Reds, Reds_r, Set1,
Set1_r, Set2, Set2_r, Set3, Set3_r, Spectral, Spectral_r, Wistia, Wistia_r, YlGn, YlGnBu,
YlGnBu_r, YlGn_r, YlOrBr,

YlOrBr_r, YlOrRd, YlOrRd_r, afmhot, afmhot_r, autumn, autumn_r, binary, binary_r, bone,
bone_r, brg, brg_r, bwr, bwr_r,

cividis, cividis_r, cool, cool_r, coolwarm, coolwarm_r, copper, copper_r, cubehelix, cubehelix_r,
flag, flag_r, gist_earth,

gist_earth_r, gist_gray, gist_gray_r, gist_heat, gist_heat_r, gist_ncar, gist_ncar_r, gist_rainbow,


gist_rainbow_r, gist_stern,

7. Control violin order by passing an explicit order:

# Python program to illustrate


# violinplot using inbuilt data-set
# given in seaborn

# importing the required module


import seaborn

# use to set style of background of plot


[Link](style="whitegrid")

# loading data-set
tips = seaborn.load_dataset("tips")

[Link](x="time", y="tip", data=tips,


order=["Dinner", "Lunch"])

Output:

8. Adding the palette attributes:


Using the palette we can generate the point with different colors. In this below example we can see
the palette can be responsible for a generate the violinplot with different colormap values.

Syntax:

[Link]( x, y, data, palette=”color_name”)


# Python program to illustrate
# violinplot using inbuilt data-set
# given in seaborn

# importing the required module


import seaborn

# use to set style of background of plot


[Link](style="whitegrid")

# loading data-set
tips = seaborn.load_dataset("tips")

[Link](x='day', y='total_bill',
data=tips, hue='time', palette='pastel')

Output:

9. Adding the saturation parameter:


Proportion of the original saturation to draw colors at. Large patches often look better with slightly
desaturated colors, but set this to 1 if you want the plot colors to perfectly match the input color
spec.

Syntax:

[Link](x, y, data, saturation)

# Python program to illustrate


# violinplot using inbuilt data-set
# given in seaborn

# importing the required module


import seaborn

# use to set style of background of plot


[Link](style="whitegrid")

# loading data-set
tips = seaborn.load_dataset("tips")

[Link](x ='day', y ='tip',


data = tip, saturation =0.03)

Output:
10. Adding color parameter:
It will Color for all the elements or seed for a gradient palette.

Syntax:

[Link](x, y, data, color)

# Python program to illustrate


# violinplot using inbuilt data-set
# given in seaborn

# importing the required module


import seaborn

# use to set style of background of plot


[Link](style="whitegrid")

# loading data-set
tips = seaborn.load_dataset("tips")

[Link](x ='day', y ='tip', data = tip, color = "Yellow")

Output:

11. Scale the violin width by the number of observations in each bin:

# Python program to illustrate


# Python program to illustrate
# violinplot using inbuilt data-set
# given in seaborn

# importing the required module


import seaborn

# use to set style of background of plot


[Link](style="whitegrid")

# loading data-set
tips = seaborn.load_dataset("tips")

[Link](x="day", y="total_bill", hue="sex",


data=tip, palette="Set2", split=True,
scale="count")

Output:

Comment N nishan… Follow 3

Article Tags: Python Python-Seaborn

Company Explore Tutorials Courses Offline Preparation


About Us POTD Programming ML and Data Centers Corner
Corporate & Communications Address: Legal Practice Languages Science Noida Interview
Privacy Problems DSA DSA and Bengaluru Corner
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Policy Connect Web Placements Pune Aptitude
Pradesh (201305) Careers Blogs Technology Web Hyderabad Puzzles
Contact Us 90% AI, ML & Development Kolkata GfG 160
Registered Address:
Corporate Refund Data Science Data Science System Design
K 061, Tower K, Gulshan Vivante Solution on DevOps Programming
Apartment, Sector 137, Noida, Gautam
Campus Courses CS Core Languages
Buddh Nagar, Uttar Pradesh, 201305
Training Subjects DevOps &
Program GATE Cloud
School GATE
Subjects Trending
Software and Technologies
Tools
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
Search...
Tutorials
Practice V
Jobs
Python Tutorial Data Types Interview Questions Examples Quizzes DSA Python Data Science NumPy Pandas Practice

Stripplot using Seaborn in Python


Last Updated : 23 Jul, 2025

Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides
beautiful default styles and color palettes to make statistical plots more attractive. It is built on top of
the matplotlib library and also closely integrated into the data structures from pandas.

Strip plot

A strip plot is drawn on its own. It is a good complement to a boxplot or violinplot in cases where all
observations are shown along with some representation of the underlying distribution. It is used to
draw a scatter plot based on the category.

Syntax: [Link](*, x=None, y=None, hue=None, data=None, order=None,


hue_order=None, jitter=True, dodge=False, orient=None, color=None, palette=None, size=5,
edgecolor='gray', linewidth=0, ax=None, **kwargs)

Parameters:

x, y, hue: Inputs for plotting long-form data.


data: Dataset for plotting.
order: It is the order to plot the categorical levels in.
color: It is the color for all of the elements, or seed for a gradient palette

Returns: This method returns the Axes object with the plot drawn onto it.

Example: Basic visualization of “tips” dataset using stripplot()

import seaborn
import [Link] as plt

[Link](style = 'whitegrid')
tip = seaborn.load_dataset("tips")

[Link](x="day", y="total_bill", data=tip)

[Link]()

Output:
Draw a single horizontal strip plot using Stripplot
If we use only one data variable instead of two data variables then it means that the axis denotes
each of these data variables as an axis.
X denotes an x-axis and y denote a y-axis.
Syntax:

[Link](x)

Code:

# Python program to illustrate


# Stripplot using inbuilt data-set
# given in seaborn

# importing the required module


import seaborn
import [Link] as plt

# use to set style of background of plot


[Link](style = 'whitegrid')

# loading data-set
tips = seaborn.load_dataset("tips")
[Link](x=tips["total_bill"])

Output:
Draw strip plot using jitter parameter
jitter can be used to provide displacements along the horizontal axis, which is useful when there are
large clusters of data points. You can specify the amount of jitter (half the width of the uniform
random variable support), or just use True for a good default.
Syntax:

[Link](x, y, data, jitter)

Code:

# Python program to illustrate


# Stripplot using inbuilt data-set
# given in seaborn

# importing the required module


import seaborn
import [Link] as plt

# use to set style of background of plot


[Link](style = 'whitegrid')

# loading data-set
tips = seaborn.load_dataset("tips")

[Link](x="day", y="total_bill", data=tips, jitter=0.1)

Output:
Draw outlines around the data points using linewidth
Width of the gray lines that frame the plot elements. Whenever we increase linewidth than the point
also will increase automatically.
Syntax:

[Link](x, y, data, linewidth)

# Python program to illustrate


# Stripplot using inbuilt data-set
# given in seaborn

# importing the required module


import seaborn
import [Link] as plt

# use to set style of background of plot


[Link](style = 'whitegrid')

# loading data-set
tips = seaborn.load_dataset("tips")

[Link](y="total_bill", x="day", data=tips,


linewidth=3)

Output:
We can change the color with edgecolor

[Link](y="total_bill", x="day", data=tips,


linewidth=2,edgecolor='green')

Output:

Draw strip plot using hue parameter


While the points are plotted in two dimensions, another dimension can be added to the plot by
coloring the points according to a third variable.
Syntax:

[Link](x, y, hue, data);

# Python program to illustrate


# Stripplot using inbuilt data-set
# given in seaborn

# importing the required module


import seaborn
import [Link] as plt

# use to set style of background of plot


[Link](style = 'whitegrid')

# loading data-set
tips = seaborn.load_dataset("tips")

[Link](x="sex", y="total_bill", hue="day", data=tips)

Output:
Draw each level of the hue variable at different locations on the major categorical axis

When using hue nesting, setting dodge should be True will separate the strips for different hue
levels along the categorical axis. And Palette is used for the different levels of the hue variable.
Syntax:

[Link](x, y, data, hue, palette, dodge)

[Link](x="day", y="total_bill", hue="smoker",


data=tips, palette="Set2", dodge=True)

Output:

Possible values of palette are :

Accent, Accent_r, Blues, Blues_r, BrBG, BrBG_r, BuGn, BuGn_r, BuPu, BuPu_r,

CMRmap, CMRmap_r, Dark2, Dark2_r, GnBu, GnBu_r, Greens, Greens_r, Greys, Greys_r,
OrRd, OrRd_r, Oranges, Oranges_r, PRGn, PRGn_r, Paired, Paired_r, Pastel1, Pastel1_r, Pastel2,

Pastel2_r, PiYG, PiYG_r, PuBu, PuBuGn, PuBuGn_r, PuBu_r, PuOr, PuOr_r, PuRd, PuRd_r,
Purples,

Purples_r, RdBu, RdBu_r, RdGy, RdGy_r, RdPu, RdPu_r, RdYlBu, RdYlBu_r, RdYlGn, RdYlGn_r,
Reds,

Reds_r, Set1, Set1_r, Set2, Set2_r, Set3, Set3_r, Spectral, Spectral_r, Wistia, Wistia_r, YlGn,

YlGnBu, YlGnBu_r, YlGn_r, YlOrBr, YlOrBr_r, YlOrRd, YlOrRd_r, afmhot, afmhot_r, autumn,
autumn_r,

binary, binary_r, bone, bone_r, brg, brg_r, bwr, bwr_r, cividis, cividis_r, cool, cool_r, coolwarm,

coolwarm_r, copper, copper_r, cubehelix, cubehelix_r, flag, flag_r, gist_earth, gist_earth_r,

gist_gray, gist_gray_r, gist_heat, gist_heat_r, gist_ncar, gist_ncar_r, gist_rainbow,


gist_rainbow_r,

gist_stern, gist_stern_r, gist_yarg, gist_yarg_r, gnuplot, gnuplot2, gnuplot2_r, gnuplot_r,

gray, gray_r, hot, hot_r, hsv, hsv_r, icefire, icefire_r, inferno, inferno_r, jet, jet_r, magma,

Plotting large points and different aesthetics With marker and alpha
parameter
We will use alpha to manage transparency of the data point, and use marker for marker to customize
the data point.

import seaborn
import [Link] as plt

[Link](style = 'whitegrid')

tips = seaborn.load_dataset("tips")

[Link](x="day", y="total_bill", hue="smoker",


data=tips, palette="Set1", size=20,
marker="s", alpha=0.2)

[Link]()

Output:
Comment S shubh… Follow 4

Article Tags: Python Python-Seaborn

Company Explore Tutorials Courses Offline Preparation


About Us POTD Programming ML and Data Centers Corner
Corporate & Communications Address: Legal Practice Languages Science Noida Interview
Privacy Problems DSA DSA and Bengaluru Corner
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Policy Connect Web Placements Pune Aptitude
Pradesh (201305) Careers Blogs Technology Web Hyderabad Puzzles
Contact Us 90% AI, ML & Development Kolkata GfG 160
Registered Address:
Corporate Refund Data Science Data Science System Design
K 061, Tower K, Gulshan Vivante Solution on DevOps Programming
Apartment, Sector 137, Noida, Gautam
Campus Courses CS Core Languages
Buddh Nagar, Uttar Pradesh, 201305
Training Subjects DevOps &
Program GATE Cloud
School GATE
Subjects Trending
Software and Technologies
Tools

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved


Search...
Tutorials
Practice V
Jobs
Python Tutorial Data Types Interview Questions Examples Quizzes DSA Python Data Science NumPy Pandas Practice

Swarmplot using Seaborn in Python


Last Updated : 2 Nov, 2022

Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides
beautiful default styles and color palettes to make statistical plots more attractive. It is built on the
top of the matplotlib library and also closely integrated into the data structures from pandas.
Swarm Plot
Seaborn swarmplot is probably similar to stripplot, only the points are adjusted so it won't get
overlap to each other as it helps to represent the better representation of the distribution of values. A
swarm plot can be drawn on its own, but it is also a good complement to a box, preferable because
the associated names will be used to annotate the axes. This type of plot sometimes known as
“beeswarm”.

Syntax: [Link](x=None, y=None, hue=None, data=None, order=None,


hue_order=None, dodge=False, orient=None, color=None, palette=None, size=5,
edgecolor='gray', linewidth=0, ax=None, **kwargs)

Parameters:
x, y, hue: Inputs for plotting long-form data.
data: Dataset for plotting.
color: Color for all of the elements
size: Radius of the markers, in points.

Example 1: Basic visualization of “fmri” dataset using swarmplot()

import seaborn

[Link](style='whitegrid')
fmri = seaborn.load_dataset("fmri")

[Link](x="timepoint",
y="signal",
data=fmri)

Output:
Example 2: Grouping data points on the basis of category, here as region and event.

import seaborn

[Link](style='whitegrid')
fmri = seaborn.load_dataset("fmri")

[Link](x="timepoint",
y="signal",
hue="region",
data=fmri)

Output:

Example 3: Basic visualization of “tips” dataset using swarmplot()

import seaborn

[Link](style='whitegrid')
tip = seaborn.load_dataset('tips')

[Link](x='day', y='tip', data=tip)

Output:
Grouping variables in Seaborn Swarmplot with different attributes
1. Draw a single horizontal swarm plot using only one axis:
If we use only one data variable instead of two data variables then it means that the axis denotes
each of these data variables as an axis.
X denotes an x-axis and y denote a y-axis.
Syntax:

[Link](x)

# Python program to illustrate


# swarmplot using inbuilt data-set
# given in seaborn

# importing the required module


import seaborn

# use to set style of background of plot


[Link](style="whitegrid")

# loading data-set
tips = seaborn.load_dataset("tips")

[Link](x=tips["total_bill"])

Output:

2. Draw horizontal swarms:


In the above example we see how to plot single horizontal swarm plot and here can perform multiple
horizontal swarm plot with exchange the data variable with another axis.

# Python program to illustrate


# Python program to illustrate
# swarmplot using inbuilt data-set
# given in seaborn

# importing the required module


import seaborn

# use to set style of background of plot


[Link](style="whitegrid")

# loading data-set
tips = seaborn.load_dataset("tips")

[Link](x="total_bill", y="day", data=tips)

Output:

3. Using hue parameter:


While the points are plotted in two dimensions, another dimension can be added to the plot by
coloring the points according to a third variable.
Syntax:

[Link](x, y, hue, data);

# Python program to illustrate


# swarmplot using inbuilt data-set
# given in seaborn

# importing the required module


import seaborn

# use to set style of background of plot


[Link](style="whitegrid")

# loading data-set
tips = seaborn.load_dataset("tips")

[Link](x="day", y="total_bill", hue="time", data=tips)

Output:
4. Draw outlines around the data points using linewidth:
Width of the gray lines that frame the plot elements. Whenever we increase linewidth than the point
also will increase automatically.
Syntax:

[Link](x, y, data, linewidth)

# Python program to illustrate


# swarmplot using inbuilt data-set
# given in seaborn

# importing the required module


import seaborn

# use to set style of background of plot


[Link](style="whitegrid")

# loading data-set
tips = seaborn.load_dataset("tips")

[Link](x="day", y="total_bill", data=tips,


linewidth=2)

Output:

We can change the color with edgecolor:

[Link](y="total_bill", x="day", data=tips,


linewidth=2,edgecolor='green')
Output:

5. Draw each level of the hue variable at different locations on the major categorical axis:
When using hue nesting, setting dodge should be True will separate the point for different hue levels
along the categorical axis. And Palette is used for the different levels of the hue variable.
Syntax:

[Link](x, y, data, hue, palette, dodge)

# Python program to illustrate


# swarmplot using inbuilt data-set
# given in seaborn

# importing the required module


import seaborn

# use to set style of background of plot


[Link](style="whitegrid")

# loading data-set
tips = seaborn.load_dataset("tips")

[Link](x="day", y="total_bill", hue="smoker",


data=tips, palette="Set2", dodge=True)

Output:

Possible values of palette are:


Accent, Accent_r, Blues, Blues_r, BrBG, BrBG_r, BuGn, BuGn_r, BuPu, BuPu_r, CMRmap,
CMRmap_r, Dark2, Dark2_r,

GnBu, GnBu_r, Greens, Greens_r, Greys, Greys_r, OrRd, OrRd_r, Oranges, Oranges_r, PRGn,
PRGn_r, Paired, Paired_r,

Pastel1, Pastel1_r, Pastel2, Pastel2_r, PiYG, PiYG_r, PuBu, PuBuGn, PuBuGn_r, PuBu_r, PuOr,
PuOr_r, PuRd, PuRd_r,

Purples, Purples_r, RdBu, RdBu_r, RdGy, RdGy_r, RdPu, RdPu_r, RdYlBu, RdYlBu_r, RdYlGn,
RdYlGn_r, Reds, Reds_r, Set1,

Set1_r, Set2, Set2_r, Set3, Set3_r, Spectral, Spectral_r, Wistia, Wistia_r, YlGn, YlGnBu,
YlGnBu_r, YlGn_r, YlOrBr,

YlOrBr_r, YlOrRd, YlOrRd_r, afmhot, afmhot_r, autumn, autumn_r, binary, binary_r, bone,
bone_r, brg, brg_r, bwr, bwr_r,

cividis, cividis_r, cool, cool_r, coolwarm, coolwarm_r, copper, copper_r, cubehelix, cubehelix_r,
flag, flag_r, gist_earth,

gist_earth_r, gist_gray, gist_gray_r, gist_heat, gist_heat_r, gist_ncar, gist_ncar_r, gist_rainbow,


gist_rainbow_r, gist_stern,

6. Plotting large points and different aesthetics With marker and alpha parameter:
We will use alpha to manage transparency of the data point, and use marker for marker to customize
the data point.

# Python program to illustrate


# swarmplot using inbuilt data-set
# given in seaborn

# importing the required module


import seaborn

# use to set style of background of plot


[Link](style="whitegrid")

# loading data-set
tips = seaborn.load_dataset("tips")

[Link](x="day", y="total_bill", hue="smoker",


data=tips, palette="Set2", size=20, marker="D",
edgecolor="gray", alpha=.25)

Output:
7. Control swarm order by passing an explicit order:

# Python program to illustrate


# swarmplot using inbuilt data-set
# given in seaborn

# importing the required module


import seaborn

# use to set style of background of plot


[Link](style="whitegrid")

# loading data-set
tips = seaborn.load_dataset("tips")

[Link](x="time", y="tip", data=tips,


order=["Dinner", "Lunch"])

Output:

8. Adding size attributes.


Using size we can generate the point and we can produce points with different sizes.
Syntax:

[Link]( x, y, data, size)

# Python program to illustrate


# swarmplot using inbuilt data-set
# given in seaborn

# importing the required module


import seaborn

# use to set style of background of plot


[Link](style="whitegrid")

# loading data-set
tips = seaborn.load_dataset("tips")

[Link](x='day', y='total_bill', data=tips,


hue='smoker', size=10)

Output:

9. Adding the palette attributes:


Using the palette we can generate the point with different colors. In this below example we can see
the palette can be responsible for a generate the swarmplot with different colormap values.

Syntax:

[Link]( x, y, data, palette=”color_name”)

# Python program to illustrate


# swarmplot using inbuilt data-set
# given in seaborn

# importing the required module


import seaborn

# use to set style of background of plot


[Link](style="whitegrid")

# loading data-set
tips = seaborn.load_dataset("tips")

[Link](x='day', y='total_bill', data=tips,


hue='time', palette='pastel')

Output:
Comment N nishan… Follow 2

Article Tags: Python Python-Seaborn

Company Explore Tutorials Courses Offline Preparation


About Us POTD Programming ML and Data Centers Corner
Corporate & Communications Address: Legal Practice Languages Science Noida Interview
Privacy Problems DSA DSA and Bengaluru Corner
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Policy Connect Web Placements Pune Aptitude
Pradesh (201305) Careers Blogs Technology Web Hyderabad Puzzles
Contact Us 90% AI, ML & Development Kolkata GfG 160
Registered Address:
Corporate Refund Data Science Data Science System Design
K 061, Tower K, Gulshan Vivante Solution on DevOps Programming
Apartment, Sector 137, Noida, Gautam
Campus Courses CS Core Languages
Buddh Nagar, Uttar Pradesh, 201305
Training Subjects DevOps &
Program GATE Cloud
School GATE
Subjects Trending
Software and Technologies
Tools

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved


Search...
Tutorials
Practice V
Jobs
Python Tutorial Data Types Interview Questions Examples Quizzes DSA Python Data Science NumPy Pandas Practice

Python - [Link]() method


Last Updated : 15 Jul, 2025

Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides
beautiful default styles and color palettes to make statistical plots more attractive. It is built on the
top of matplotlib library and also closely integrated to the data structures from pandas.
[Link]() method
[Link]() method is used to draw a categorical plot onto a FacetGrid.

Syntax : [Link](x=None, y=None, hue=None, data=None, row=None, col=None,


col_wrap=None, estimator=, ci=95, n_boot=1000, units=None, seed=None, order=None,
hue_order=None, row_order=None, col_order=None, kind='strip', height=5, aspect=1,
orient=None, color=None, palette=None, legend=True, legend_out=True, sharex=True,
sharey=True, margin_titles=False, facet_kws=None, **kwargs) Parameters : This method is
accepting the following parameters that are described below:

x, y : This parameter take names of variables in data, Inputs for plotting long-form data.
hue : (optional)This parameter take column name for colour encoding
data : This parameter take DataFrame, Long-form (tidy) dataset for plotting. Each column
should correspond to a variable, and each row should correspond to an observation.
row, col : (optional) This parameter take names of variables in data, Categorical variables
that will determine the faceting of the grid.
col_wrap : (optional) This parameter take integer value, “Wrap” the column variable at this
width, so that the column facets span multiple rows. Incompatible with a row facet.
estimator : (optional) This parameter take callable that maps vector -> scalar, Statistical
function to estimate within each categorical bin.
ci : (optional) This parameter take float or “sd” or None value, Size of confidence intervals to
draw around estimated values. If “sd”, skip bootstrapping and draw the standard deviation of
the observations. If None, no bootstrapping will be performed, and error bars will not be
drawn.
n_boot : (optional) This parameter take integer value, Number of bootstrap iterations to use
when computing confidence intervals.
units : (optional) This parameter take name of variable in data or vector data, Identifier of
sampling units, which will be used to perform a multilevel bootstrap and account for
repeated measures design.
seed : (optional) This parameter take integer value, [Link], or
[Link], Seed or random number generator for reproducible
bootstrapping.
order, hue_order : (optional) This parameter take lists of strings, Order to plot the
categorical levels in, otherwise the levels are inferred from the data objects.
row_order, col_order: (optional) This parameter take lists of strings, Order to organize the
rows and/or columns of the grid in, otherwise the orders are inferred from the data objects.
kind : (optional) This parameter take string value, The kind of plot to draw (corresponds to
the name of a categorical plotting function. Options are: “point”, “bar”, “strip”, “swarm”, “box”,
“violin”, or “boxen”.
height : (optional) This parameter take float value, Height (in inches) of each facet.
aspect : (optional) This parameter take float value, Aspect ratio of each facet, so that aspect
* height gives the width of each facet in inches.
orient : (optional) This parameter take value that should be “v” | “h”, Orientation of the plot
(vertical or horizontal). This is usually inferred from the dtype of the input variables, but can
be used to specify when the “categorical” variable is a numeric or when plotting wide-form
data.
color : (optional) This parameter take matplotlib color, Color for all of the elements, or seed
for a gradient palette.
palette : (optional) This parameter take palette name, list, or dict, Colors to use for the
different levels of the hue variable. Should be something that can be interpreted by
color_palette(), or a dictionary mapping hue levels to matplotlib colors.
legend : (optional) This parameter take boolean value, If True and there is a hue variable,
draw a legend on the plot.
legend_out : (optional) This parameter take boolean value, If True, the figure size will be
extended, and the legend will be drawn outside the plot on the center right.
share{x, y} : (optional) This parameter take bool, ‘col’, or ‘row’, If true, the facets will share y
axes across columns and/or x axes across rows.
margin_titles : (optional) This parameter take boolean value, If True, the titles for the row
variable are drawn to the right of the last column. This option is experimental and may not
work in all cases.
facet_kws : (optional) This parameter take dictionary object, Dictionary of other keyword
arguments to pass to FacetGrid.
kwargs : This parameter take key, value pairings, Other keyword arguments are passed
through to the underlying plotting function.

Returns : This method returns the FacetGrid object with the plot on it for further tweaking.

Note: For downloading the Tips dataset Click Here. Below examples illustrate the factorplot()
method of the seaborn library. Example 1 :

# importing the required library


import pandas as pd
import seaborn as sns
import [Link] as plt

# read a csv file


df = pd.read_csv('[Link]')

# point plot(by default)


[Link](x ='size', y ='tip', data = df)

# Show the plot


[Link]()

Output :
Example 2 :

# importing the required library


import pandas as pd
import seaborn as sns
import [Link] as plt

# read a csv file


df = pd.read_csv('[Link]')

# point plot using hue attribute


# for colouring out points
# according to the sex
[Link](x ='size', y ='tip',
hue = 'sex', data = df)

# Show the plot


[Link]()

Output :

Comment A ankthon Follow 2

Article Tags: Python Python-Seaborn

Company Explore Tutorials Courses Offline Preparation


About Us POTD Programming ML and Data Centers Corner
Corporate & Communications Address: Legal Practice Languages Science Noida Interview
Problems DSA Bengaluru Corner
A-143, 7th Floor, Sovereign Corporate Privacy Connect Web DSA and Pune Aptitude
Tower, Sector- 136, Noida, Uttar Policy Blogs Technology Placements Hyderabad Puzzles
Pradesh (201305)
Careers 90% AI, ML & Web Kolkata GfG 160
Registered Address: Contact Us Refund Data Science Development System Design

K 061, Tower K, Gulshan Vivante Corporate on DevOps Data Science


Apartment, Sector 137, Noida, Gautam Solution Courses CS Core Programming
Buddh Nagar, Uttar Pradesh, 201305 Campus Subjects Languages
Training GATE DevOps &
Program School Cloud
Subjects GATE
Software and Trending
Tools Technologies

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved


Search...
Tutorials
Practice V
Jobs
Python Tutorial Data Types Interview Questions Examples Quizzes DSA Python Data Science NumPy Pandas Practice

How to Make Histograms with Density Plots with Seaborn histplot?


Last Updated : 29 Oct, 2021

Histograms are visualization tools that represent the distribution of a set of continuous data. In a
histogram, the data is divided into a set of intervals or bins (usually on the x-axis) and the count of
data points that fall into each bin corresponding to the height of the bar above that bin. These bins
may or may not be equal in width but are adjacent (with no gaps).
A density plot (also known as kernel density plot) is another visualization tool for evaluating data
distributions. It can be considered as a smoothed histogram. The peaks of a density plot help display
where values are concentrated over the interval. There are a variety of smoothing techniques. Kernel
Density Estimation (KDE) is one of the techniques used to smooth a histogram.
Seaborn is a data visualization library based on matplotlib in Python. In this article, we will use
[Link]() to plot a histogram with a density plot.

Syntax: [Link](data, x, y, hue, stat, bins, binwidth, discrete, kde, log_scale)

Parameters:-

data: input data in the form of Dataframe or Numpy array


x, y (optional): key of the data to be positioned on the x and y axes respectively
hue (optional): semantic data key which is mapped to determine the color of plot elements
stat (optional): count, frequency, density or probability

Return: This method returns the matplotlib axes with the plot drawn on it.

Example 1: We will generate the data using the [Link]() method.

# Import necessary libraries


import seaborn as sns
import numpy as np
import pandas as pd

# Generating dataset of random numbers


[Link](1)
num_var = [Link](1000)
num_var = [Link](num_var, name = "Numerical Variable")

# Plot histogram
[Link](data = num_var, kde = True)

Output:
By default kde parameter of [Link] is set to false. So, by setting the kde to true, a kernel
density estimate is computed to smooth the distribution and a density plotline is drawn.
Example 2: Let us use the sample dataset, Penguins, from the Seaborn library in this example. This
dataset shows the characteristics (body mass, flipper length, bill length gender) of different penguin
species on different islands.

# Import necessary libraries


import numpy as np
import pandas as pd
import seaborn as sns

# Load dataset
penguins = sns.load_dataset("penguins")

# Plot histogram
[Link](data = penguins, x = "body_mass_g", kde = True)

Output:

We can also visualize the distribution of body mass for multiple species in a single plot. The hue
parameter maps the semantic variable 'species'.

# Plot Histogram
[Link](data = penguins, x = "body_mass_g", kde = True, hue = "species")

Output:

Example 3: This example uses the sample dataset, Tips, from the Seaborn library which records the
tips received by a restaurant server. It consists of the tip received total bill or cost of the meal, gender
of the customer, size of the customer party, day, time and whether a smoker is present at the party or
not. Instead of the count of data points, the histogram in this example is normalized so that each
bar’s height shows a probability.

# Import necessary libraries


import numpy as np
import pandas as pd
import seaborn as sns
# Load dataset
tips = sns.load_dataset("tips")

# Plot histogram
[Link](data = tips, x = "size", stat = "probability", discrete = True)

Output:

Comment A akshis… Follow 4

Article Tags: Python Python-Seaborn

Company Explore Tutorials Courses Offline Preparation


About Us POTD Programming ML and Data Centers Corner
Corporate & Communications Address: Legal Practice Languages Science Noida Interview
Privacy Problems DSA DSA and Bengaluru Corner
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Policy Connect Web Placements Pune Aptitude
Pradesh (201305) Careers Blogs Technology Web Hyderabad Puzzles
Contact Us 90% AI, ML & Development Kolkata GfG 160
Registered Address:
Corporate Refund Data Science Data Science System Design
K 061, Tower K, Gulshan Vivante Solution on DevOps Programming
Apartment, Sector 137, Noida, Gautam
Campus Courses CS Core Languages
Buddh Nagar, Uttar Pradesh, 201305
Training Subjects DevOps &
Program GATE Cloud
School GATE
Subjects Trending
Software and Technologies
Tools

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved


Search...
Tutorials
Practice V
Jobs
Python Tutorial Data Types Interview Questions Examples Quizzes DSA Python Data Science NumPy Pandas Practice

Python - [Link]() method


Last Updated : 15 Jul, 2025

Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface
for drawing attractive and informative statistical graphics. Seaborn helps resolve the two major
problems faced by Matplotlib; the problems are ?
Default Matplotlib parameters
Working with data frames

As Seaborn compliments and extends Matplotlib, the learning curve is quite gradual. If you know
Matplotlib, you are already half-way through Seaborn.

[Link]() :

Draw a plot of two variables with bivariate and univariate graphs. This function provides a convenient
interface to the 'JointGrid' class, with several canned plot kinds. This is intended to be a fairly
lightweight wrapper; if you need more flexibility, you should use :class:'JointGrid' directly.

Syntax: [Link](x, y, data=None, kind='scatter', stat_func=None, color=None,


height=6, ratio=5, space=0.2, dropna=True, xlim=None, ylim=None, joint_kws=None,
marginal_kws=None, annot_kws=None, **kwargs)

Parameters: The description of some main parameters are given below:

x, y: These parameters take Data or names of variables in "data".

data: (optional) This parameter take DataFrame when "x" and "y" are variable names.

kind: (optional) This parameter take Kind of plot to draw.

color: (optional) This parameter take Color used for the plot elements.

dropna: (optional) This parameter take boolean value, If True, remove observations that are
missing from "x" and "y".

Return: jointgrid object with the plot on it.

Below is the implementation of above method:


Example 1:

# importing required packages


import seaborn as sns
import [Link] as plt
# loading dataset
data = sns.load_dataset("attention")

# draw jointplot with


# hex kind
[Link](x = "solutions", y = "score",
kind = "hex", data = data)
# show the plot
[Link]()

# This code is contributed


# by Deepanshu Rustagi.

Output:

Example 2:

# importing required packages


import seaborn as sns
import [Link] as plt

# loading dataset
data = sns.load_dataset("mpg")

# draw jointplot with


# scatter kind
[Link](x = "mpg", y = "acceleration",
kind = "scatter", data = data)
# show the plot
[Link]()

# This code is contributed


# by Deepanshu Rustagi.

Output:
Example 3:

# importing required packages


import seaborn as sns
import [Link] as plt

# loading dataset
data = sns.load_dataset("exercise")

# draw jointplot with


# kde kind
[Link](x = "id", y = "pulse",
kind = "kde", data = data)
# Show the plot
[Link]()

# This code is contributed


# by Deepanshu Rustagi.

Output:
Example 4:

# importing required packages


import seaborn as sns
import [Link] as plt

# loading dataset
data = sns.load_dataset("titanic")

# draw jointplot with


# reg kind
[Link](x = "age", y = "fare",
kind = "reg", data = data,
dropna = True)

# show the plot


[Link]()

# This code is contributed


# by Deepanshu Rustagi.

Output:
Comment D deepa… Follow 3

Article Tags: Python Python-Seaborn

Company Explore Tutorials Courses Offline Preparation


About Us POTD Programming ML and Data Centers Corner
Corporate & Communications Address: Legal Practice Languages Science Noida Interview
Privacy Problems DSA DSA and Bengaluru Corner
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Policy Connect Web Placements Pune Aptitude
Pradesh (201305) Careers Blogs Technology Web Hyderabad Puzzles
Contact Us 90% AI, ML & Development Kolkata GfG 160
Registered Address:
Corporate Refund Data Science Data Science System Design
K 061, Tower K, Gulshan Vivante Solution on DevOps Programming
Apartment, Sector 137, Noida, Gautam
Campus Courses CS Core Languages
Buddh Nagar, Uttar Pradesh, 201305
Training Subjects DevOps &
Program GATE Cloud
School GATE
Subjects Trending
Software and Technologies
Tools

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved


Search...
Tutorials
Practice V
Jobs
a Visualization Tutorial With Python Types Matplotlib Altair Plotly Computer Vision OpenCV Computer Graphics Tutorial Deep Learn

Python - [Link]() method


Last Updated : 15 Jul, 2025

[Link]() method is used for visualizing relationships between multiple variables in a dataset.
By creating a grid of scatter plots it helps to identify how different features interact with each other
to identify patterns, correlations and trends in data. In this article, we will see how to implement
[Link]() in python.

Syntax: [Link](data, **kwargs)

Here data refers to the dataset we want to visualize and kwargs represent additional optional
parameters that can be customized for different visualizations.

Below are the most commonly used parameters:

Value
Arguments
Description

Dataframe where each column is a variable and


data DataFrame
each row is an observation.

Variable in data to map plot aspects to different


hue string (variable name), optional
colors.

Set of colors for mapping the hue variable. Can


palette dict or seaborn color palette
be a dictionary for custom color mapping

Allows you to specify which variables to use for


{x, y}_vars the rows and columns of the plot to create a lists of variable names, optional
custom layout.

Drop missing values from the data before


dropna boolean, optional
plotting.

Now we will implement this using the tips dataset. This dataset contains information about
restaurant tips, total bill amount, tip amount, customer details like sex and day of the week, etc. Also
we will be using Seaborn and Matplotlib libraries to it.

Example 1: Pairplot with Hue by Day


We will use hue parameter to color-code points based on the day column. This helps to distinguish
between different days of the week.
import seaborn
import [Link] as plt
df = seaborn.load_dataset('tips')
[Link](df, hue ='day')
[Link]()

Output :

Pairplot by Hue

A grid of scatter plots showing the relationships between the numerical features in the tips dataset
with color coding based on the day column is formed.

Example 2: Pairplot with Custom Palette by Sex


We will use the hue and palette parameter to color-code points based on the sex column helps in
distinguishing between male and female customers. Here we defined colour palette as blue and pink
using custom_palette.

import seaborn
import [Link] as plt
df = seaborn.load_dataset('tips')
custom_palette = {'Male': 'lightblue', 'Female': 'pink'}
[Link](df, hue='sex', palette=custom_palette)
[Link]()
Output :

Pairplot using Custom Palette

Scatter plots will be color-coded based on the sex column which allows us to distinguish between
male and female customers.

Example 3: Pairplot with Specific Variables


We can focus on specific variables in the tips dataset. Here we visualize only the total_bill, tip and size
features using {x, y}_vars parameter.

import seaborn
import [Link] as plt
df = seaborn.load_dataset('tips')
[Link](df[['total_bill', 'tip', 'size']])
[Link]()

Output :
Specific variables

This will display a pairplot for the selected columns (total_bill, tip and size) excluding other features
from the visualization.

Comment D deepa… Follow 14

Article Tags: Data Visualization AI-ML-DS Python-Seaborn AI-ML-DS With Python

Company Explore Tutorials Courses Offline Preparation


About Us POTD Programming ML and Data Centers Corner
Corporate & Communications Address: Legal Practice Languages Science Noida Interview
Privacy Problems DSA DSA and Bengaluru Corner
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Policy Connect Web Placements Pune Aptitude
Pradesh (201305) Careers Blogs Technology Web Hyderabad Puzzles
Contact Us 90% AI, ML & Development Kolkata GfG 160
Registered Address:
Corporate Refund Data Science Data Science System Design
K 061, Tower K, Gulshan Vivante Solution on DevOps Programming
Apartment, Sector 137, Noida, Gautam
Courses CS Core Languages
Buddh Nagar, Uttar Pradesh, 201305
Subjects
Campus GATE DevOps &
Training School Cloud
Program Subjects GATE
Software and Trending
Tools Technologies

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved


Search...
Tutorials
Practice V
Jobs
Data Science Tutotrial Maths Statistics Big Data Machine Learning AI NumPy Pandas Data Analysis Deep Learning

Seaborn Kdeplot – A Comprehensive Guide


Last Updated : 23 Jul, 2025

Kernel Density Estimate (KDE) Plot is a powerful tool for estimating the probability density function
of continuous or non-parametric data. KDE plot is implemented through the kdeplot function in
Seaborn. This article explores the syntax and usage of kdeplot in Python, focusing on one-dimensional
and bivariate scenarios for efficient data visualization.

Table of Content

What is KDE plot?


How to visualize KDE Plot using Seaborn?
KDE Plot of Iris Dataset
Conclusion
Frequently Asked Questions (FAQs)

What is KDE plot?


Kernel Density Estimate (KDE) Plot allows to estimate the probability density function of the
continuous or non-parametric from our data set curve in one or more dimensions it means we can
create plot a single graph for multiple samples which helps in more efficient data visualization.

In order to use the Seaborn module, we need to install the module using the below command:

!pip install seaborn

Syntax: [Link](x=None, *, y=None, vertical=False, palette=None, **kwargs)

Parameters:

x, y : vectors or keys in data

vertical : boolean (True or False)

data : [Link], [Link], mapping, or sequence

How to visualize KDE Plot using Seaborn?


We learn the usage of some parameters through some specific examples:

Importing Libraries
First import the corresponding library

import pandas as pd
import seaborn as sb
import numpy as np
from matplotlib import pyplot as plt
%matplotlib inline

Draw a simple one-dimensional kde image:

Let's see the Kde of our variable x-axis and y-axis, so let pass the x variable into the kdeplot()
methods.

# data x and y axis for seaborn


x= [Link](200)
y = [Link](200)

# Kde for x var


[Link](x)

Output:

Then after check for y-axis.

[Link](y)

Output:

Use Shade to fill the area covered by curve:

We can highlight the plot using shade to the area covered by the curve. If True, shadow processing is
performed in the area below the kde curve, and color controls the color of the curve and shadow.

[Link](x, shade = True)


Output:

You can change the Shade color with color attributes:

[Link](x, shade = True , color = "Green")

Output:

Use Vertical to draw indicates whether to draw on the X axis or on the Y axis

[Link](x, vertical = True)

Output:

Bivariate Kdeplot for two variables:

Simple pass the two variables into the [Link]() methods.

[Link](x,y)

Output:
Shade the area covered by a curve with shade attributes:

[Link](x,y, shade = True)

Output:

Now you can change the color with cmap attributes:

[Link](x,y, cmap = "winter_r")

Output:

Use of Cbar: If True, add a colorbar to annotate the color mapping in a bivariate plot. Note: Does not
currently support plots with a hue variable well.

[Link](x, y, shade=True, cbar=True)

Output:

KDE Plot of Iris Dataset


Let see the example with Iris Dataset which is plot distributions for each column of a wide-form
dataset:

Iris data set consists of 3 different types of irises’ (Setosa, Versicolour, and Virginica) petal and sepal
length, stored in a 150x4 [Link]

Loading the iris dataset for Kdeplot:


iris = sns.load_dataset('iris')
iris

Output:

Bivariate Kdeplot for two variables of iris:

Once we have species set then if we want to simply calculate the petal_length and petal_width then
Simple pass the two variables(Setosa and virginica ) into the [Link]() methods.

setosa = [Link][[Link]=="setosa"]
virginica = [Link][[Link] == "virginica"]
[Link](setosa.petal_length, setosa.petal_width)

Output:

See another example if we want to calculate another variable attribute which is sepal_width and
sepal_length.

[Link](setosa.sepal_width, setosa.sepal_length)

Output:

If we pass the two separate Kdeplot with different variable:

[Link](setosa.petal_length, setosa.petal_width)
[Link](virginica.petal_length, virginica.petal_width)

Output:
Conclusion
In summary, kdeplot in Seaborn offers a versatile approach to visualize probability density functions,
aiding in the exploration of one or more dimensions in datasets. Whether shading areas, adjusting
colors, or applying it to real-world datasets like Iris, kdeplot stands as a valuable tool for data
scientists and analysts.

Comment K kumar… Follow 3

Article Tags: Data Science python Python-Seaborn

Company Explore Tutorials Courses Offline Preparation


About Us POTD Programming ML and Data Centers Corner
Corporate & Communications Address: Legal Practice Languages Science Noida Interview
Privacy Problems DSA DSA and Bengaluru Corner
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Policy Connect Web Placements Pune Aptitude
Pradesh (201305) Careers Blogs Technology Web Hyderabad Puzzles
Contact Us 90% AI, ML & Development Kolkata GfG 160
Registered Address:
Corporate Refund Data Science Data Science System Design
K 061, Tower K, Gulshan Vivante Solution on DevOps Programming
Apartment, Sector 137, Noida, Gautam
Campus Courses CS Core Languages
Buddh Nagar, Uttar Pradesh, 201305
Training Subjects DevOps &
Program GATE Cloud
School GATE
Subjects Trending
Software and Technologies
Tools

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved


Search...
Tutorials
Practice V
Jobs
Python Tutorial Data Types Interview Questions Examples Quizzes DSA Python Data Science NumPy Pandas Practice

Seaborn Heatmap - A comprehensive guide


Last Updated : 23 Jul, 2025

A heatmap is a graphical representation of data where individual values are represented by color
intensity. It is widely used in data analysis and visualization to identify patterns, correlations and
trends within a dataset. Heatmaps in Seaborn can be plotted using the [Link]() function,
which offers extensive customization options. Let's explore different methods to create and enhance
heatmaps using Seaborn.

Example: The following example demonstrates how to create a simple heatmap using the Seaborn
library.

import numpy as np
import seaborn as sns
import [Link] as plt

# Generating a 10x10 matrix of random numbers


data = [Link](1, 100, (10, 10))

[Link](data)
[Link]()

Basic heatmap

Explanation: This will produce a heatmap where the intensity of color represents the magnitude of
values in the matrix.

Syntax of [Link]()
[Link](data, *, vmin=None, vmax=None, cmap=None, center=None,
annot_kws=None, linewidths=0, linecolor='white', cbar=True, **kwargs)

Parameters:
data: A 2D dataset that can be coerced into a NumPy ndarray.
vmin, vmax: Values to anchor the colormap; if not specified, they are inferred from the data.
cmap: The colormap for mapping data values to colors.
center: Value at which to center the colormap when plotting divergent data.
annot: If True, displays numerical values inside the cells.
fmt: String format for annotations.
linewidths: Width of the lines separating cells.
linecolor: Color of the separating lines.
cbar: Whether to display a color bar.

Note: All parameters except data are optional.

Returns: returns an object of type [Link]

Examples
Example 1: By setting vmin and vmax, we explicitly define the range of values that influence the
color scaling in the heatmap. This ensures consistency across multiple heatmaps, preventing
extreme values from distorting the visualization.

import numpy as np
import seaborn as sns
import [Link] as plt

data = [Link](1, 100, (10, 10))

[Link](data, vmin=30, vmax=70)


[Link]()

Output:

Anchoring the Colormap

Explanation: The parameters vmin=30 and vmax=70 define the limits of the color scale range.
Values lower than 30 are represented by the lowest intensity color, while values higher than 70 are
mapped to the highest intensity color.

Example 2: The cmap parameter allows us to modify the color scheme of the heatmap, improving its
visual appeal and making it easier to distinguish between different values.

import numpy as np
import seaborn as sns
import [Link] as plt

data = [Link](1, 100, (10, 10))

[Link](data, cmap='tab20')
[Link]()

Output:
Choosing a Colormap

Explanation: The argument cmap='tab20' sets a categorical colormap. Sequential colormaps (Blues,
Reds, Greens) suit continuous data, while diverging colormaps (coolwarm, RdBu) highlight
variations.

Example 3: By setting the center parameter, we ensure that a specific value (such as the mean or
median) appears neutral in the colormap. This adjustment makes deviations above and below this
value more distinguishable.

import numpy as np
import seaborn as sns
import [Link] as plt

data = [Link](1, 100, (10, 10))

[Link](data, cmap='coolwarm', center=50)


[Link]()

Output:

Centering the Colormap

Explanation: The center=50 parameter sets 50 as a neutral color. Values above it are shaded in one
color (e.g., red) and below in another (e.g., blue), making it useful for highlighting deviations from a
reference point.

Advanced customizations in seaborn heatmap


Seaborn's heatmap() function provides various options for customization, allowing users to enhance
visualization by adjusting color schemes, labels, scaling and spacing.

import [Link] as plt


import seaborn as sns
import numpy as np
import [Link] as mcolors

data = [Link](10, 10) * 100

[Link](figsize=(12, 8)) # Adjust figure size

[Link](
data,
xticklabels=list("ABCDEFGHIJ"), # Custom x-axis labels
yticklabels=False, # Hide y-axis labels
norm=[Link](), # Logarithmic scaling
cmap="coolwarm", # Color map
linewidths=0.5 # Cell spacing
)

# Add title and labels


[Link]("Custom Heatmap", fontsize=16)
[Link]("X-axis")
[Link]("Y-axis")

[Link]()

Output:

Advanced customization

Explanation:
[Link](figsize=(12, 8)) enlarges the figure for better visibility.
xticklabels=list("ABCDEFGHIJ") replaces default labels with A-J.
yticklabels=False removes y-axis labels for clarity.
norm=[Link]() enhances contrast for varied data.
cmap="coolwarm" uses a blue-to-red gradient.
linewidths=0.5 adds thin separation lines.
[Link]("Custom Heatmap", fontsize=16) adds a title with a readable font size.
[Link]("X-axis") & [Link]("Y-axis") labels the axes for clear understanding.

Comment Y Yash_R Follow 15

Article Tags: Python Python-Seaborn

Company Explore Tutorials Courses Offline Preparation


About Us POTD Programming ML and Data Centers Corner
Corporate & Communications Address: Legal Practice Languages Science Noida Interview
Privacy Problems DSA DSA and Bengaluru Corner
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Policy Connect Web Placements Pune Aptitude
Pradesh (201305) Careers Blogs Technology Web Hyderabad Puzzles
Contact Us Development Kolkata GfG 160
Registered Address:
K 061, Tower K, Gulshan Vivante Corporate 90% AI, ML & Data Science System Design
Apartment, Sector 137, Noida, Gautam Solution Refund Data Science Programming
Buddh Nagar, Uttar Pradesh, 201305
Campus on DevOps Languages
Training Courses CS Core DevOps &
Program Subjects Cloud
GATE GATE
School Trending
Subjects Technologies
Software and
Tools

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved


Search...
Tutorials
Practice V
Jobs
Python Tutorial Data Types Interview Questions Examples Quizzes DSA Python Data Science NumPy Pandas Practice

How to create a correlation heatmap in Python?


Last Updated : 23 Jul, 2025

Seaborn is a powerful Python library based on Matplotlib, designed for data visualization. It provides
an intuitive way to represent data using statistical graphics. One such visualization is a heatmap,
which is used to display data variation through a color palette. In this article, we focus on correlation
heatmaps, and how Seaborn, in combination with Pandas and Matplotlib, can be used to generate
one for a DataFrame.

Installation

To use Seaborn, you need to install it along with Pandas and Matplotlib. If you haven't installed
Seaborn yet, you can do so using the following commands:

pip install seaborn

Alternatively, if you are using Anaconda:

conda install seaborn

Seaborn is typically included in Anaconda distributions and should work just by importing if your IDE
is configured with Anaconda.

What is correlation heatmap?


A correlation heatmap is a 2D graphical representation of a correlation matrix between multiple
variables. It uses colored cells to indicate correlation values, making patterns and relationships
within data visually interpretable. The color intensity of each cell represents the strength of the
correlation:

1 (or close to 1): Strong positive correlation (dark colors)


0: No correlation (neutral colors)
-1 (or close to -1): Strong negative correlation (light colors)

Steps to create a correlation heatmap


The following steps show how a correlation heatmap can be produced:

Import all required modules.


Load the dataset.
Compute the correlation matrix.
Plot the heatmap using Seaborn.
Display the heatmap using Matplotlib.
For plotting a heatmap, we use the heatmap() function from the Seaborn module.

Example 1: Correlation Heatmap for Bestseller Novels Dataset

This example uses a dataset downloaded from Kaggle containing information about bestselling
novels on Amazon.

# Import necessary modules


import [Link] as plt
import pandas as pd
import seaborn as sns

# Load dataset
data = pd.read_csv("C:\\Users\\Vanshi\\Desktop\\[Link]")

# Compute correlation matrix


co_mtx = [Link](numeric_only=True)

# Print correlation matrix


print(co_mtx)

# Plot correlation heatmap


[Link](co_mtx, cmap="YlGnBu", annot=True)

# Display heatmap
[Link]()

Output

Explanation:
Importing Libraries: We import Matplotlib for visualization, Pandas for handling data and
Seaborn for plotting.
Loading Dataset: We use pd.read_csv() to load the dataset.
Computing Correlation Matrix: The .corr() method calculates the correlation between numerical
columns.
Plotting the Heatmap: [Link]() creates the visualization with color coding.
Displaying the Heatmap: [Link]() renders the heatmap.

Example 2: Correlation Heatmap for NASA Exoplanet Dataset

This example uses an exoplanet space research dataset compiled by NASA.

# Import necessary modules


import [Link] as mp
import pandas as pd
import seaborn as sb
# Load dataset
data = pd.read_csv("C:\\Users\\Vanshi\\Desktop\\[Link]")

# Plotting correlation heatmap


dataplot = [Link]([Link](numeric_only=True))

# Displaying heatmap
[Link]()

Output

Explanation:
Loading Dataset: The dataset is loaded using pd.read_csv().
Computing Correlation Matrix: .corr() function is applied to identify relationships between
numerical variables.
Plotting with Seaborn: heatmap() function is used to visualize the correlation, with
cmap="coolwarm" to adjust the color scheme.
Displaying the Heatmap: [Link]() function displays the plotted heatmap.

Comment V vanshi… Follow 15

Article Tags: Misc Python Python-Seaborn

Company Explore Tutorials Courses Offline Preparation


About Us POTD Programming ML and Data Centers Corner
Corporate & Communications Address: Legal Practice Languages Science Noida Interview
Privacy Problems DSA DSA and Bengaluru Corner
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Policy Connect Web Placements Pune Aptitude
Pradesh (201305) Careers Blogs Technology Web Hyderabad Puzzles
Contact Us 90% AI, ML & Development Kolkata GfG 160
Registered Address:
Corporate Refund Data Science Data Science System Design
K 061, Tower K, Gulshan Vivante Solution on DevOps Programming
Apartment, Sector 137, Noida, Gautam
Campus Courses CS Core Languages
Buddh Nagar, Uttar Pradesh, 201305
Training Subjects DevOps &
Program GATE Cloud
School GATE
Subjects Trending
Software and Technologies
Tools

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved


Search...
Tutorials
Practice V
Jobs
Python Tutorial Data Types Interview Questions Examples Quizzes DSA Python Data Science NumPy Pandas Practice

How to create a Triangle Correlation Heatmap in seaborn - Python?


Last Updated : 21 Mar, 2024

Seaborn is a Python library that is based on matplotlib and is used for data visualization. It provides a
medium to present data in a statistical graph format as an informative and attractive medium to
impart some information. A heatmap is one of the components supported by seaborn where variation
in related data is portrayed using a color palette. This article centrally focuses on a correlation
heatmap and how seaborn in combination with pandas and matplotlib can be used to generate one
for a dataframe.

Installation

Like any another Python library, seaborn can be easily installed using pip:

pip install seaborn

This library is a part of Anaconda distribution and usually works just by import if your IDE is
supported by Anaconda, but it can be installed too by the following command:

conda install seaborn

Triangle correlation heatmap


A correlation heatmap is a heatmap that shows a 2D correlation matrix between two discrete
dimensions, using colored cells to represent data from usually a monochromatic scale. The values of
the first dimension appear as the rows of the table while of the second dimension as a column. The
color of the cell is proportional to the number of measurements that match the dimensional value.
This makes correlation heatmaps ideal for data analysis since it makes patterns easily readable and
highlights the differences and variation in the same data. A correlation heatmap, like a regular
heatmap is assisted by a colorbar making data easily readable and comprehensible.
A correlation heatmap is a rectangular representation of data and it repeats the same data
description twice because the categories are repeated on both axis for computing analysis. Hence,
the same result is obtained twice. A correlation heatmap that presents data only once without
repetition that is categories are correlated only once is known as a triangle correlation heatmap.
Since data is symmetric across the diagonal from left-top to right bottom the idea of obtaining a
triangle correlation heatmap is to remove data above it so that it is depicted only once. The elements
on the diagonal are the parts where categories of the same type correlate.
For plotting heatmap method of the seaborn module will be used. Along with that mask, argument
will be passed. Mask is a heatmap attribute that takes a dataframe or a boolean array as an argument
and displays only those positions which are marked as False or where masking is provided to be
False.
Syntax:

heatmap(data, vmin, vmax, center, cmap,............................................................)


Except for data all other attributes are optional and data obviously will be the data to be plotted. The
data here has to be passed with corr() method to generate a correlation heatmap. Also, corr() itself
eliminates columns which will be of no use while generating a correlation heatmap and selects those
which can be used.
For masking, here an array using NumPy is being generated as shown below:

[Link](np.ones_like())

first, the ones_like() method of NumPy module will generate an array of size same as that of our data
to be plotted containing only number one. Then, triu() method of the NumPy module will turn the
matrix so formed into an upper triangular matrix, i.e. elements above the diagonal will be 1 and
below, and on it will be 0. Masking will be applied to places where 1(True) is set.
The following steps show how a triangle correlation heatmap can be produced:
Import all required modules first
Import the file where your data is stored
Plot a heatmap
Mask the part of the heatmap that shouldn't be displayed
Display it using matplotlib

Example 1:
For the example given below, here a dataset downloaded from [Link] is being used. The plot
shows data related to bestseller novels of amazon.

# import modules
import [Link] as mp
import pandas as pd
import seaborn as sb
import numpy as np

# import file with data


data = pd.read_csv("C:\\Users\\Vanshi\\Desktop\\gfg\\[Link]")

# creating mask
mask = [Link](np.ones_like([Link]()))

# plotting a triangle correlation heatmap


dataplot = [Link]([Link](), cmap="YlGnBu", annot=True, mask=mask)

# displaying heatmap
[Link]()

Output:

Example 2:
The dataset used in this example is an exoplanet space research dataset compiled by nasa.

# import modules
import [Link] as mp
import pandas as pd
import seaborn as sb
import numpy as np
# import file with data
data = pd.read_csv("C:\\Users\\Vanshi\\Desktop\\gfg\\[Link]")

# applying mask
mask = [Link](np.ones_like([Link]()))

# plotting a triangle correlation heatmap


dataplot = [Link]([Link](), mask=mask)

# displaying heatmap
[Link]()

Output:

Comment V vanshi… Follow 5

Article Tags: Technical Scripter Python Technical Scripter 2020 Python-Seaborn

Company Explore Tutorials Courses Offline Preparation


About Us POTD Programming ML and Data Centers Corner
Corporate & Communications Address: Legal Practice Languages Science Noida Interview
Privacy Problems DSA DSA and Bengaluru Corner
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Policy Connect Web Placements Pune Aptitude
Pradesh (201305) Careers Blogs Technology Web Hyderabad Puzzles
Contact Us 90% AI, ML & Development Kolkata GfG 160
Registered Address:
Corporate Refund Data Science Data Science System Design
K 061, Tower K, Gulshan Vivante Solution on DevOps Programming
Apartment, Sector 137, Noida, Gautam
Campus Courses CS Core Languages
Buddh Nagar, Uttar Pradesh, 201305
Training Subjects DevOps &
Program GATE Cloud
School GATE
Subjects Trending
Software and Technologies
Tools

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved


Search...
Tutorials
Practice V
Jobs
Python Tutorial Data Types Interview Questions Examples Quizzes DSA Python Data Science NumPy Pandas Practice

ColorMaps in Seaborn HeatMaps


Last Updated : 25 Nov, 2020

Colormaps are used to visualize heatmaps effectively and easily. One might use different sorts of
colormaps for different kinds of heatmaps. In this article, we will look at how to use colormaps while
working with seaborn heatmaps.
Sequential Colormaps: We use sequential colormaps when the data values(numeric) goes from high
to low and only one of them is important for the analysis.
Example of sequential colormaps:

[Link](sns.color_palette("Greens",12))

Sequential color palette

[Link](sns.color_palette("Blues",12))

Sequential color palette

Note that we have used sns.color_palette() to construct a colormap and [Link]() to display the
colors present in the colormap. The following example shows how to implement a sequential
colormap on a seaborn heatmap.
Example:

import seaborn as sns


import numpy as np

[Link](0)

# generates random values


data = [Link](12, 12)

# creating a colormap
colormap = sns.color_palette("Greens")

# creating a heatmap using the colormap


ax = [Link](data, cmap=colormap)

Output:

Heatmap with a sequential colormap


Since "Greens" is an inbuilt colormap in seaborn, can also directly pass "Greens" to the cmap
argument:

import seaborn as sns


import numpy as np

[Link](0)

data = [Link](12, 12)


ax = [Link](data, cmap="Greens")

Output:

Heatmap with a sequential colormap

Note that our colormap now has a continuous color intensity unlike the one before which had a
discrete intensity of green for a range of values. Here is a closer look at both of the colormaps
generated in the above-mentioned heatmaps:

Discrete(left) and Continuous(right) Colormaps

Diverging Colormaps: They are used to represent numeric values that go from high to low(and vice-
versa), and both high and low values are of interest.
Here are some diverging colormaps present in seaborn:

[Link](sns.color_palette("PiYG", 12))

Diverging color palette

[Link](sns.color_palette("coolwarm", 12))

Example: The following example shows how to implement a diverging colormap on a seaborn
heatmap.
import seaborn as sns
import numpy as np

[Link](0)

data = [Link](12, 12)


ax = [Link](data, cmap="PiYG")

Output:

Comment S sareen… Follow 2

Article Tags: Python Python-Seaborn

Company Explore Tutorials Courses Offline Preparation


About Us POTD Programming ML and Data Centers Corner
Corporate & Communications Address: Legal Practice Languages Science Noida Interview
Privacy Problems DSA DSA and Bengaluru Corner
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Policy Connect Web Placements Pune Aptitude
Pradesh (201305) Careers Blogs Technology Web Hyderabad Puzzles
Contact Us 90% AI, ML & Development Kolkata GfG 160
Registered Address:
Corporate Refund Data Science Data Science System Design
K 061, Tower K, Gulshan Vivante Solution on DevOps Programming
Apartment, Sector 137, Noida, Gautam
Campus Courses CS Core Languages
Buddh Nagar, Uttar Pradesh, 201305
Training Subjects DevOps &
Program GATE Cloud
School GATE
Subjects Trending
Software and Technologies
Tools

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved


Search...
Tutorials
Practice V
Jobs
Python Tutorial Data Types Interview Questions Examples Quizzes DSA Python Data Science NumPy Pandas Practice

How to add a frame to a seaborn heatmap figure in Python?


Last Updated : 3 Jan, 2021

A heatmap is a graphical representation of data where values are depicted by color. They make it
easy to understand complex data at a glance. Heatmaps can be easily drawn using seaborn in
python. In this article, we are going to add a frame to a seaborn heatmap figure in Python.

Syntax: [Link](data, *, vmin=None, vmax=None, cmap=None, center=None,


annot_kws=None, linewidths=0, linecolor=’white’, cbar=True, **kwargs)

Important Parameters:

data: 2D dataset that can be coerced into an ndarray.


linewidths: Width of the lines that will divide each cell.
linecolor: Color of the lines that will divide each cell.
cbar: Whether to draw a colorbar.

All the parameters except data are optional.

Returns: An object of type [Link]._subplots.AxesSubplot

Create a heatmap

To draw the heatmap we will use the in-built data set of seaborn. Seaborn has many in-built data
sets like [Link], [Link], [Link], [Link]. We can also make our data set it should
just be a rectangular ndarray.

# Import libraries
import seaborn as sns
import [Link] as plt

# Preparing dataset
example = sns.load_dataset("flights")
example = [Link]("month", "year",
"passengers")

# Creating plot
res = [Link](example)

# show plot
[Link]()

Output:
basic heatmap

There are two ways of drawing the frame around a heatmap:

1. Using axhline and axvline.


2. Using spines (more optimal)

Method 1: Using axhline and axvline


The [Link]() and [Link]() function in axes module of matplotlib library is used to add a
horizontal and vertical line across the axis respectively.
We can draw two horizontal lines from y=0 and from y= number of rows in our dataset and it will
draw a frame covering two sides of our heatmap. Then we can draw two vertical lines from x=0 and
x=number of columns in our dataset and it will draw a frame covering the remaining two sides so our
heatmap will have a complete frame.
Note: It is not an optimal way to draw a frame as when we increase the line width is does not
consider when it is overlapping the heatmap.
Example 1.

# Import libraries
import seaborn as sns
import [Link] as plt

# Preparing dataset
example = sns.load_dataset("flights")
example = [Link]("month", "year",
"passengers")

# Creating plot
res = [Link](example, cmap = "BuPu")

# Drawing the frame


[Link](y = 0, color='k',linewidth = 10)
[Link](y = [Link][1], color = 'k',
linewidth = 10)

[Link](x = 0, color = 'k',


linewidth = 10)

[Link](x = [Link][0],
color = 'k', linewidth = 10)

# show plot
[Link]()

Output:
Example 2:

# Import libraries
import seaborn as sns
import [Link] as plt
import numpy as np

# Preparing dataset
example = [Link](10, 12)

# Creating plot
res = [Link](example, cmap = "magma",
linewidths = 0.5)

# Drawing the frame


[Link](y = 0, color = 'k',
linewidth = 15)

[Link](y = 10, color = 'k',


linewidth = 15)

[Link](x = 0, color = 'k',


linewidth = 15)

[Link](x = 12, color = 'k',


linewidth = 15)
# show plot
[Link]()

Output:

Method 2: Using spines


Spines are the lines connecting the axis tick marks and noting the boundaries of the data area. They
can be placed at arbitrary positions.
Example 1:
width of the line can be changed using the set_linewidth parameter which accepts a float value as an
argument.

# Import libraries
import seaborn as sns
import [Link] as plt

# Preparing dataset
example = sns.load_dataset("flights")
example = [Link]("month", "year",
"passengers")

# Creating plot
res = [Link](example, cmap = "Purples")

# Drawing the frame


for _, spine in [Link]():
spine.set_visible(True)
spine.set_linewidth(5)

# show plot
[Link]()

Output:

Example 2:
We can specify the style of the frame using the set_linestyle parameter of the spine(solid, dashed,
dashdot, dotted).

# Import libraries
import seaborn as sns
import [Link] as plt
import numpy as np

# Preparing dataset
example = [Link](10, 12)

# Creating plot
res = [Link](example, cmap = "Greens",
linewidths = 2,
linecolor = "white")

# Drawing the frame


for _, spine in [Link]():
spine.set_visible(True)
spine.set_linewidth(3)
spine.set_linestyle("dashdot")

# show plot
[Link]()

Output:
Comment H hg070… Follow 1

Article Tags: Python Python-Seaborn

Company Explore Tutorials Courses Offline Preparation


About Us POTD Programming ML and Data Centers Corner
Corporate & Communications Address: Legal Practice Languages Science Noida Interview
Privacy Problems DSA DSA and Bengaluru Corner
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Policy Connect Web Placements Pune Aptitude
Pradesh (201305) Careers Blogs Technology Web Hyderabad Puzzles
Contact Us 90% AI, ML & Development Kolkata GfG 160
Registered Address:
Corporate Refund Data Science Data Science System Design
K 061, Tower K, Gulshan Vivante Solution on DevOps Programming
Apartment, Sector 137, Noida, Gautam
Campus Courses CS Core Languages
Buddh Nagar, Uttar Pradesh, 201305
Training Subjects DevOps &
Program GATE Cloud
School GATE
Subjects Trending
Software and Technologies
Tools

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved


Search...
Tutorials
Practice V
Jobs
Python Tutorial Data Types Interview Questions Examples Quizzes DSA Python Data Science NumPy Pandas Practice

How to increase the size of the annotations of a seaborn heatmap in


Python?
Last Updated : 23 Jul, 2025

Prerequisites: Seaborn
Seaborn is a Python library that is based on matplotlib and is used for data visualization. It provides a
medium to present data in a statistical graph format as an informative and attractive medium to
impart some information. A heatmap is one of the components supported by seaborn where variation
in related data is portrayed using a color palette.
Annotations are text that appears on a heatmap cell which represents what that cell represents. The
annotations follow a default font size but it can be changed using the annot_kws parameter of
heatmap() function, annot_kws is a dictionary type parameter that accepts value for the key named
size. The value set to this key defines the size of the annotations, but there are certain conditions that
has to met to increase the size of the annotations:
annot parameter of the heatmap() function must be set to True.
annot_kws parameter must be set with required size.

Syntax: [Link](data, *, vmin=None, vmax=None, cmap=None, center=None,


annot_kws=None, linewidths=0, linecolor=’white’, cbar=True, **kwargs)

Important Parameters:

data: 2D dataset that can be coerced into an ndarray.


vmin, vmax: Values to anchor the colormap, otherwise they are inferred from the data and
other keyword arguments.
cmap: The mapping from data values to color space.
center: The value at which to center the colormap when plotting divergent data.
annot: If True, write the data value in each cell.
fmt: String formatting code to use when adding annotations.
linewidths: Width of the lines that will divide each cell.
linecolor: Color of the lines that will divide each cell.
cbar: Whether to draw a colorbar.

All the parameters except data are optional.

Returns: An object of type [Link]._subplots.AxesSubplot

Approach

Import module
Create or load data
Call heatmap() function with annot set to True.
Set size to annot_kws parameter.
Display plot

Implementation using this approach is given below:


Example 1:

# Importing Required Libraries


import pandas as pd
import numpy as np
import seaborn as sb
import [Link] as mtb

data = pd.read_csv("[Link]")

[Link]([Link](), annot=True, annot_kws={'size': 15})

[Link]()

Output:

For setting the size, one must be careful while setting size value. Providing a very large number will
magnify annotations way too much making them difficult to read, understand, they may even fall over
each other making the heatmap unreadable.
Implementation of this is shown below:
Example 2:

# Importing Required Libraries


import pandas as pd
import numpy as np
import seaborn as sb
import [Link] as mtb

data = pd.read_csv("[Link]")

[Link]([Link](), annot=True, annot_kws={'size': 25})

[Link]()

Output:
Comment V vanshi… Follow 2

Article Tags: Technical Scripter Python Technical Scripter 2020 Python-Seaborn

Company Explore Tutorials Courses Offline Preparation


About Us POTD Programming ML and Data Centers Corner
Corporate & Communications Address: Legal Practice Languages Science Noida Interview
Privacy Problems DSA DSA and Bengaluru Corner
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Policy Connect Web Placements Pune Aptitude
Pradesh (201305) Careers Blogs Technology Web Hyderabad Puzzles
Contact Us 90% AI, ML & Development Kolkata GfG 160
Registered Address:
Corporate Refund Data Science Data Science System Design
K 061, Tower K, Gulshan Vivante Solution on DevOps Programming
Apartment, Sector 137, Noida, Gautam
Campus Courses CS Core Languages
Buddh Nagar, Uttar Pradesh, 201305
Training Subjects DevOps &
Program GATE Cloud
School GATE
Subjects Trending
Software and Technologies
Tools

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved


Search...
Tutorials
Practice V
Jobs
Python Tutorial Data Types Interview Questions Examples Quizzes DSA Python Data Science NumPy Pandas Practice

Hierarchically-clustered Heatmap in Python with Seaborn Clustermap


Last Updated : 23 Jul, 2025

Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides
beautiful default styles and color palettes to make statistical plots more attractive. It is built on the
top of matplotlib library and also closely integrated into the data structures from pandas.
What is Clustering?
Clustering is basically grouping data based on relationships among the variables in the data.
Clustering algorithms help in getting structured data in unsupervised learning. The most common
types of clustering are shown below.

Clustering_types

Here we are going to see hierarchical clustering especially Agglomerative(bottom-up) hierarchical


clustering. In Agglomerative clustering, we start with considering each data point as a cluster and
then repeatedly combine two nearest clusters into larger clusters until we are left with a single
cluster. The graph we plot after performing agglomerative clustering on data is called Dendrogram.
Plotting Hierarchically clustered Heatmaps
Coming to the heat map, it is a graphical representation of data where values are represented using
colors. Variation in the intensity of color depicts how data is clustered or varies over space.
The clustermap() function of seaborn plots a hierarchically-clustered heat map of the given matrix
dataset. It returns a clustered grid index.
Below are some examples which depict the hierarchically-clustered heat map from a dataset:
In the Flights dataset the data(Number of passengers) is clustered based on month and year:
Example 1:

# Importing the library


import seaborn as sns
from sunbird.categorical_encoding import frequency_encoding

# Load dataset
data = sns.load_dataset('flights')

# Categorical encoding
frequency_encoding(data, 'month')

# Clustering data row-wise and


# changing color of the map.
[Link](data, figsize=(7, 7))

Output :
The legend to the left of the cluster map indicates information about the cluster map e.g bright color
indicates more passengers and dark color indicates fewer passengers.
Example 2:

# Importing the library


import seaborn as sns
from sunbird.categorical_encoding import frequency_encoding

# Load dataset
data = sns.load_dataset('flights')

# Categorical encoding
frequency_encoding(data, 'month')

# Clustering data row-wise and


# changing color of the map.
[Link](data, cmap='coolwarm', figsize=(7, 7))

Output:
Here we have changed the colors of the cluster map.

Comment T tejalka… Follow 1

Article Tags: Python Python-Seaborn

Company Explore Tutorials Courses Offline Preparation


About Us POTD Programming ML and Data Centers Corner
Corporate & Communications Address: Legal Practice Languages Science Noida Interview
Privacy Problems DSA DSA and Bengaluru Corner
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Policy Connect Web Placements Pune Aptitude
Pradesh (201305) Careers Blogs Technology Web Hyderabad Puzzles
Contact Us 90% AI, ML & Development Kolkata GfG 160
Registered Address:
Corporate Refund Data Science Data Science System Design
K 061, Tower K, Gulshan Vivante Solution on DevOps Programming
Apartment, Sector 137, Noida, Gautam
Campus Courses CS Core Languages
Buddh Nagar, Uttar Pradesh, 201305
Training Subjects DevOps &
Program GATE Cloud
School GATE
Subjects Trending
Software and Technologies
Tools

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved


Search...
Tutorials
Practice V
Jobs
s Tutorial Python for DA Data Visualization Maths for DA Interview Questions Projects Machine Learning Deep Learning NLP Artificia

Exploring Correlation in Python


Last Updated : 6 Feb, 2026

Correlation is one of the most commonly used statistical measures to understand how variables are
related to each other. In Python, correlation helps identify whether two variables move together,
move in opposite directions or have no relationship at all.

Helps understand data relationships.


Useful in feature selection for ML models.
Detects multicollinearity.
Supports better decision-making.

Correlation

Correlation measures the strength and direction of the relationship between two numerical variables.
Value ranges from -1 to +1

+1: Perfect positive relationship. That means both variables increase or decrease together.
Example: Height and weight
-1: Perfect negative relationship meaning one variable increases while the other decreases.
Example: Price and demand
0: No relationship or no correlation means no visible relationship between variables. Example:
Shoe size and exam marks

Common Correlation Methods in Python

1. Pearson Correlation
Pearson Correlation measures linear relationship between two continuous variables.

Range: -1 to +1
Assumes normally distributed data

2. Spearman Correlation

Spearman Correlation measures monotonic relationship using ranks.

Works with non-linear data


Suitable for ordinal data

3. Kendall Correlation

Kendall Correlation measures rank consistency between variables.

More robust for small datasets

Correlation Using Python


Python provides built-in tools through pandas and visualization libraries to compute and analyze
correlation efficiently. Understanding correlation helps build better models and gain deeper insights
from data.

1. Sample Dataset

Here we will create a sample dataset and use it using pandas dataframe. We will use seaborn and
matplotlib to visualize the relationship.

import pandas as pd
import seaborn as sns
import [Link] as plt

data = {
'Math': [78, 85, 96, 80, 86],
'Science': [88, 90, 94, 82, 89],
'English': [72, 75, 78, 70, 74]
}

df = [Link](data)
df

Output:

Data
2. Pearson Correlation

Computes pairwise correlation between columns


Default method is Pearson
Higher values indicate stronger correlation

pearson_corr = [Link](method='pearson')
print(pearson_corr)

[Link](pearson_corr, annot=True, cmap='coolwarm')


[Link]("Pearson Correlation Heatmap")
[Link]()

Output:

Pearson Correlation

The above output shows that the relationship between maths, science and english.

3. Spearman Correlation

Converts values to ranks before correlation


Suitable for non-linear but monotonic relationships
Useful when data is not normally distributed

spearman_corr = [Link](method='spearman')
print(spearman_corr)

[Link](spearman_corr, annot=True, cmap='viridis')


[Link]("Spearman Correlation Heatmap")
[Link]()

Output:

Spearman Correlation

4. Kendall Correlation

Measures agreement between rankings


Works well for small datasets

kendall_corr = [Link](method='kendall')
print(kendall_corr)

[Link](kendall_corr, annot=True, cmap='plasma')


[Link]("Kendall Correlation Heatmap")
[Link]()

Output:
Kendall Correlation

5. Correlation Between Two Columns

Returns correlation value between two specific columns


Heatmap gives a visual understanding of relationships
Darker color indicates stronger correlation

corr_value = df['Math'].corr(df['Science'])
print("Correlation between Math and Science:", corr_value)

two_col_corr = df[['Math', 'Science']].corr()

[Link](two_col_corr, annot=True, cmap='coolwarm')


[Link]("Correlation Between Math and Science")
[Link]()

Output:
Correlation Between Two Columns

Interpreting Correlation Values

Correlation Value Meaning

0.8 to 1.0 Strong positive

0.5 to 0.8 Moderate positive

0.0 to 0.5 Weak positive

0 No correlation

-0.5 to 0 Weak negative

-0.8 to -0.5 Moderate negative

-1.0 to -0.8 Strong negative

Limitations of Correlation
Only measures association
Sensitive to outliers

Applications of Correlation
Feature selection in machine learning
Financial market analysis
Medical research
Recommendation systems

Comment M mohit … Follow 13

Article Tags: Data Analysis AI-ML-DS AI-ML-DS With Python

Company Explore Tutorials Courses Offline Preparation


About Us POTD Programming ML and Data Centers Corner
Corporate & Communications Address: Legal Practice Languages Science Noida Interview
Privacy Problems DSA DSA and Bengaluru Corner
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Policy Connect Web Placements Pune Aptitude
Pradesh (201305) Careers Blogs Technology Web Hyderabad Puzzles
Contact Us 90% AI, ML & Development Kolkata GfG 160
Registered Address:
Corporate Refund Data Science Data Science System Design
K 061, Tower K, Gulshan Vivante Solution on DevOps Programming
Apartment, Sector 137, Noida, Gautam
Campus Courses CS Core Languages
Buddh Nagar, Uttar Pradesh, 201305
Training Subjects DevOps &
Program GATE Cloud
School GATE
Subjects Trending
Software and Technologies
Tools

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved


Search...
Tutorials
Practice V
Jobs
Python Tutorial Data Types Interview Questions Examples Quizzes DSA Python Data Science NumPy Pandas Practice

Seaborn - Bubble Plot


Last Updated : 23 Jul, 2025

Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides
beautiful default styles and color palettes to make statistical plots more attractive. It is built on the
top of matplotlib library and also closely integrated to the data structures from pandas.

Scatter plots are used to observe relationship between variables and uses dots to represent the
relationship between them. Bubble plots are scatter plots with bubbles (color filled circles) rather
than information focuses. Bubbles have various sizes dependent on another variable in the data.
Likewise, Bubbles can be of various color dependent on another variable in the dataset.
Let us load the required module and the simplified Iris data as a Pandas Data frame:

# import all important libraries


import [Link] as plt
import pandas as pd
import seaborn as sns

# load dataset
data=
"[Link]

# convert to dataframe
df = pd.read_csv(data)

# display top most rows


[Link]()

Output:

Scatter plot with Seaborn:

As stated earlier than, bubble is a unique form of scatter plot with bubbles as opposed to easy facts
points in scatter plot. Let us first make a simple scatter plot the usage of Seaborn’s scatterplot()
function.

# import all important libraries


import [Link] as plt
import pandas as pd
import seaborn as sns
# load dataset
data =
"[Link]

# convert to dataframe
df = pd.read_csv(data)

# display top most rows


[Link]()

# depict scatterplot illustration


sns.set_context("talk", font_scale=1.1)
[Link](figsize=(8, 6))
[Link](x="[Link]",
y="[Link]",
data=df)

# assign labels
[Link]("[Link]")
[Link]("[Link]")

Output:

Bubble plot with Seaborn scatterplot():

To make bubble plot in Seaborn, we are able to use scatterplot() function in Seaborn with a variable
specifying size argument in addition to x and y-axis variables for scatter plot.
In this bubble plot instance, we have length= ”body_mass_g”. And this will create a bubble plot with
unique bubble sizes based at the body length variable.

# import all important libraries


import [Link] as plt
import pandas as pd
import seaborn as sns

# load dataset
data =
"[Link]

# convert to dataframe
df = pd.read_csv(data)

# display top most rows


[Link]()

# depict scatter plot illustration


sns.set_context("talk", font_scale=1.1)
[Link](figsize=(10, 6))
[Link](x="[Link]",
y="[Link]",
data=df)
# Put the legend out of the figure
[Link](bbox_to_anchor=(1.01, 1), borderaxespad=0)
[Link]("[Link]")
[Link]("[Link]")
plt.tight_layout()
[Link]("Bubble_plot_Seaborn_scatterplot.png",
format='png', dpi=150)

Output:

The below example depicts a bubble plot having colored bubbles:

# import all important libraries


import [Link] as plt
import pandas as pd
import seaborn as sns

# load dataset
data=
"[Link]

# convert to dataframe
df = pd.read_csv(data)

# display top most rows


[Link]()

# depict bubble plot illustration


sns.set_context("talk", font_scale=1.2)
[Link](figsize=(10,6))
[Link](x='[Link]',
y='[Link]',
sizes=(20,500),
alpha=0.5,
data= df)
# Put the legend out of the figure
[Link](bbox_to_anchor=(1.01, 1),borderaxespad=0)

# assign labels
[Link]("[Link]")
[Link]("[Link]")

# assign title
[Link]("Bubble plot in Seaborn")

# adjust layout
plt.tight_layout()
Output:

Bubble plot with explicit size ranges Seaborn scatterplot()

We can alter the air bubble plot made with Seaborn without any problem. Something that we notice
from the bubble plot above is that the bubble size range is by all accounts little. It will be
extraordinary in the event that we could differ the littlest and biggest bubble sizes.
With the contention sizes in Seaborn's scatterplot() work, we can indicate ranges for the bubble
sizes. In this air pocket plot model underneath, we utilized sizes=(20,500).

# import all important libraries


import [Link] as plt
import pandas as pd
import seaborn as sns

# load dataset
data =
"[Link]

# convert to dataframe
df = pd.read_csv(data)

# display top most rows


[Link]()

# depict bubble plot illustration


sns.set_context("talk", font_scale=1.2)
[Link](figsize=(10, 6))
[Link](x='[Link]',
y='[Link]',
# size="body_mass_g",
sizes=(20, 500),
alpha=0.5,
hue='variety',
data=df)

# Put the legend out of the figure


[Link](bbox_to_anchor=(1.01, 1), borderaxespad=0)

# Put the legend out of the figure


[Link]("[Link]")
[Link]("[Link]")
[Link]("Bubble plot with Colors in Seaborn")
plt.tight_layout()

Output:
Presently our bubble plot looks much better with the lowest bubble comparing to the lowest weight
and the greatest bubble relates to the biggest weight. At the point when you have more factors in
the information, we can shade the bubble by the fourth factor. To color the bubble plot by a variable,
we determine tone contention.

Comment R ritikku… Follow 3

Article Tags: Python Python-Seaborn

Company Explore Tutorials Courses Offline Preparation


About Us POTD Programming ML and Data Centers Corner
Corporate & Communications Address: Legal Practice Languages Science Noida Interview
Privacy Problems DSA DSA and Bengaluru Corner
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Policy Connect Web Placements Pune Aptitude
Pradesh (201305) Careers Blogs Technology Web Hyderabad Puzzles
Contact Us 90% AI, ML & Development Kolkata GfG 160
Registered Address:
Corporate Refund Data Science Data Science System Design
K 061, Tower K, Gulshan Vivante Solution on DevOps Programming
Apartment, Sector 137, Noida, Gautam
Campus Courses CS Core Languages
Buddh Nagar, Uttar Pradesh, 201305
Training Subjects DevOps &
Program GATE Cloud
School GATE
Subjects Trending
Software and Technologies
Tools

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved


Search...
Tutorials
Practice V
Jobs
Python Tutorial Data Types Interview Questions Examples Quizzes DSA Python Data Science NumPy Pandas Practice

Python - [Link]() method


Last Updated : 15 Jul, 2025

Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides
beautiful default styles and color palettes to make statistical plots more attractive. It is built on the
top of matplotlib library and also closely integrated to the data structures from pandas.
[Link]() :
This method is used to plot the residuals of linear regression. This method will regress y on x and
then draw a scatter plot of the residuals. You can optionally fit a lowess smoother to the residual
plot, which can help in determining if there is a structure to the residuals.

Syntax: [Link](x, y, data=None, lowess=False, x_partial=None, y_partial=None,


order=1,
robust=False, dropna=True, label=None, color=None, scatter_kws=None, line_kws=None,
ax=None)

Parameters: The description of some main parameters are given below:

x: Data or column name in 'data' for the predictor variable.


y: Data or column name in 'data' for the response variable.
data: (optional) DataFrame having `x` and `y` are column names.
lowess: (optional) Fit a lowess smoother to the residual scatterplot.
dropna: (optional) This parameter takes boolean value. If True, ignore observations with
missing data when fitting and plotting.

Return: Axes with the regression plot.

Below is the implementation of above method:


Example 1:

# importing required packages


import seaborn as sns
import [Link] as plt

# loading dataset
data = sns.load_dataset("tips")

# draw residplot
[Link](x = "total_bill",
y = "tip",
data = data)

# show the plot


[Link]()

# This code is contributed


# by Deepanshu Rustagi.
Output:

Example 2:

# importing required packages


import seaborn as sns
import [Link] as plt

# loading dataset
data = sns.load_dataset("iris")

# draw residplot
# with lowess = True
[Link](x = "petal_length",
y = "petal_width",
data = data,
lowess = True)

# show the plot


[Link]()

# This code is contributed


# by Deepanshu Rustagi.

Output:

Comment D deepa… Follow 1


Article Tags: Python Python-Seaborn

Company Explore Tutorials Courses Offline Preparation


About Us POTD Programming ML and Data Centers Corner
Corporate & Communications Address: Legal Practice Languages Science Noida Interview
Privacy Problems DSA DSA and Bengaluru Corner
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Policy Connect Web Placements Pune Aptitude
Pradesh (201305) Careers Blogs Technology Web Hyderabad Puzzles
Contact Us 90% AI, ML & Development Kolkata GfG 160
Registered Address:
Corporate Refund Data Science Data Science System Design
K 061, Tower K, Gulshan Vivante Solution on DevOps Programming
Apartment, Sector 137, Noida, Gautam
Campus Courses CS Core Languages
Buddh Nagar, Uttar Pradesh, 201305
Training Subjects DevOps &
Program GATE Cloud
School GATE
Subjects Trending
Software and Technologies
Tools

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved


Search...
Tutorials
Practice V
Jobs
Python Tutorial Data Types Interview Questions Examples Quizzes DSA Python Data Science NumPy Pandas Practice

Python - [Link]() method


Last Updated : 15 Jul, 2025

Prerequisite : Fundamentals of Seaborn


Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface
for drawing attractive and informative statistical graphics. There is just something extraordinary
about a well-designed visualization. The colors stand out, the layers blend nicely together, the
contours flow throughout, and the overall package not only has a nice aesthetic quality, but it
provides meaningful insights to us as well.
[Link]()
Draw an enhanced box plot for larger datasets. This style of plot was originally named a "letter
value" plot because it shows a large number of quantiles that are defined as "letter values". It is
similar to a box plot in plotting a nonparametric representation of a distribution in which all features
correspond to actual observations. By plotting more quantiles, it provides more information about the
shape of the distribution, particularly in the tails.

Syntax : [Link](parameters)

Parameters :
x, y, hue : Inputs for plotting long-form data.
data : Dataset for plotting.
order, hue_order : Order to plot the categorical levels in, otherwise the levels are inferred
from the data objects.
orient : Orientation of the plot (vertical or horizontal).
color : Color for all of the elements, or seed for a gradient palette.
palette : Colors to use for the different levels of the hue variable.
saturation : Proportion of the original saturation to draw colors at.
width : Width of a full element when not using hue nesting, or width of all the elements for
one level of the major grouping variable.
dodge : When hue nesting is used, whether elements should be shifted along the
categorical axis.
k_depth : The number of boxes, and by extension number of percentiles, to draw.
linewidth : Width of the gray lines that frame the plot elements.
scale : Method to use for the width of the letter value boxes.
outlier_prop : Proportion of data believed to be outliers.
showfliers : If False, suppress the plotting of outliers.
ax : Axes object to draw the plot onto, otherwise uses the current Axes.
kwargs : Other keyword arguments

Returns : Returns the Axes object with the plot drawn onto it.
Below is the implementation of above method with some examples :
Example 1:

# importing packages
import seaborn as sns
import [Link] as plt

# loading dataset
data = sns.load_dataset("tips")

# plot the boxenplot


[Link](x = "day", y = "total_bill",
data = data)
[Link]()

Output :

Example 2:

# importing packages
import seaborn as sns
import [Link] as plt

# loading dataset
data = sns.load_dataset("tips")

# plot the boxenplot


# hue by sex Loading Playground...
# width of 0.8
[Link](x ="day", y = "total_bill", hue = "sex",
data = data, width = 0.8)
[Link]()

Output :
Example 3:

# importing packages
import seaborn as sns
import [Link] as plt

# loading dataset
data = sns.load_dataset("tips")

# plot the boxenplot


Loading Playground...
# orient to horizontal
[Link](x = "total_bill", y = "size",
data = data, orient ="h")
[Link]()

Output :

Comment D deepa… Follow

Article Tags: Python Python-Seaborn


Company Explore Tutorials Courses Offline Preparation
About Us POTD Programming ML and Data Centers Corner
Corporate & Communications Address: Legal Practice Languages Science Noida Interview
Privacy Problems DSA DSA and Bengaluru Corner
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Policy Connect Web Placements Pune Aptitude
Pradesh (201305) Careers Blogs Technology Web Hyderabad Puzzles
Contact Us 90% AI, ML & Development Kolkata GfG 160
Registered Address:
Corporate Refund Data Science Data Science System Design
K 061, Tower K, Gulshan Vivante Solution on DevOps Programming
Apartment, Sector 137, Noida, Gautam
Campus Courses CS Core Languages
Buddh Nagar, Uttar Pradesh, 201305
Training Subjects DevOps &
Program GATE Cloud
School GATE
Subjects Trending
Software and Technologies
Tools

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved


Search...
Tutorials
Practice V
Jobs
Python Tutorial Data Types Interview Questions Examples Quizzes DSA Python Data Science NumPy Pandas Practice

Python - [Link]() method


Last Updated : 15 Jul, 2025

Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides
beautiful default styles and color palettes to make statistical plots more attractive. It is built on the
top of matplotlib library and also closely integrated to the data structures from pandas.

[Link]() :

This method is used to show point estimates and confidence intervals using scatter plot glyphs. A
point plot represents an estimate of central tendency for a numeric variable by the position of
scatter plot points and provides some indication of the uncertainty around that estimate using
error bars.
This function always treats one of the variables as categorical and draws data at ordinal positions
(0, 1, ... n) on the relevant axis, even when the data has a numeric or date type.

Syntax: [Link](x=None, y=None, hue=None, data=None,


order=None,hue_order=None, estimator=<function mean at 0x00000193E305E828>, ci=95,
n_boot=1000, units=None, markers='o', linestyles='-', dodge=False, join=True, scale=1,
orient=None, color=None, palette=None, errwidth=None, capsize=None, ax=None, **kwargs)

Parameters: The description of some main parameters are given below:

x, y: Inputs for plotting long-form data.


hue: (optional) column name for color encoding.
data: dataframe as a Dataset for plotting.
markers: (optional) Markers to use for each of the 'hue' levels.
linestyles: (optional) Line styles to use for each of the 'hue' levels.
dodge: (optional) Amount to separate the points for each level of the 'hue' variable along the
categorical axis.
color: (optional) Color for all the elements, or seed for a gradient palette.
capsize: (optional) Width of the 'caps' on error bars.

Return: The Axes object with the plot drawn onto it.

Below is the implementation of above method:


Example 1:

# importing required packages


import seaborn as sns
import [Link] as plt
# loading dataset
data = sns.load_dataset("tips")

# draw pointplot
[Link](x = "sex",
y = "total_bill",
data = data)
# show the plot
[Link]()
# This code is contributed
# by Deepanshu Rustagi.

Output:

Example 2:

# importing required packages


import seaborn as sns
import [Link] as plt

# loading dataset
data = sns.load_dataset("tips")

# draw pointplot with


# hue = smoker
[Link](x = "sex",
y = "total_bill",
hue = "smoker",
data = data)
# show the plot
[Link]()
# This code is contributed
# by Deepanshu Rustagi.

Output :
Example 3:

# importing required packages


import seaborn as sns
import [Link] as plt

# loading dataset
data = sns.load_dataset("tips")

# draw pointplot
[Link](x = "size",
y = "total_bill",
linestyles = '-.',
markers = '^',
hue = "sex",
data = data)
# show the plot
[Link]()

# This code is contributed


# by Deepanshu Rustagi.

Output:

Comment D deepa… Follow 1


Article Tags: Python Python-Seaborn

Company Explore Tutorials Courses Offline Preparation


About Us POTD Programming ML and Data Centers Corner
Corporate & Communications Address: Legal Practice Languages Science Noida Interview
Privacy Problems DSA DSA and Bengaluru Corner
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Policy Connect Web Placements Pune Aptitude
Pradesh (201305) Careers Blogs Technology Web Hyderabad Puzzles
Contact Us 90% AI, ML & Development Kolkata GfG 160
Registered Address:
Corporate Refund Data Science Data Science System Design
K 061, Tower K, Gulshan Vivante Solution on DevOps Programming
Apartment, Sector 137, Noida, Gautam
Campus Courses CS Core Languages
Buddh Nagar, Uttar Pradesh, 201305
Training Subjects DevOps &
Program GATE Cloud
School GATE
Subjects Trending
Software and Technologies
Tools

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved

You might also like