Data Visualization With Seaborn
Data Visualization With Seaborn
🎨 Introduction to Seaborn
Seaborn is a Python data visualization library built on top of Matplotlib. It provides a
high-level interface for creating attractive and informative statistical graphics with
less code.
Seaborn Roadmap
Types of Functions
Figure Level
Axis Level
Main Classification
Relational Plot
Distribution Plot
Categorical Plot
Regression Plot
Matrix Plot
Multiplots
https://seaborn.pydata.org/api.html
1. Relational Plot
to see the statistical relation between 2 or more variables.
Bivariate Analysis
file:///C:/Users/goura/Downloads/16-Seaborn.html 1/100
2/15/25, 10:35 PM 16-Seaborn
scatterplot
lineplot
file:///C:/Users/goura/Downloads/16-Seaborn.html 2/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 3/100
2/15/25, 10:35 PM 16-Seaborn
gap = px.data.gapminder()
temp_df = gap[gap['country'] == 'India']
temp_df
file:///C:/Users/goura/Downloads/16-Seaborn.html 4/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 5/100
2/15/25, 10:35 PM 16-Seaborn
temp_df = gap[gap['country'].isin(['India','Pakistan','China'])]
temp_df
file:///C:/Users/goura/Downloads/16-Seaborn.html 6/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 7/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 8/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 9/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 10/100
2/15/25, 10:35 PM 16-Seaborn
In [13]: # facet plot -> figure level function -> work with relplot
# it will not work with scatterplot and lineplot
file:///C:/Users/goura/Downloads/16-Seaborn.html 11/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 12/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 13/100
2/15/25, 10:35 PM 16-Seaborn
2. Distribution Plots
used for univariate analysis
used to find out the distribution
Range of the observation
Central Tendency
is the data bimodal?
Are there outliers?
file:///C:/Users/goura/Downloads/16-Seaborn.html 14/100
2/15/25, 10:35 PM 16-Seaborn
histplot
kdeplot
rugplot
file:///C:/Users/goura/Downloads/16-Seaborn.html 15/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 16/100
2/15/25, 10:35 PM 16-Seaborn
# countplot
sns.displot(data=tips, x='day', kind='hist')
file:///C:/Users/goura/Downloads/16-Seaborn.html 17/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 18/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 19/100
2/15/25, 10:35 PM 16-Seaborn
Out[21]: survived pclass sex age sibsp parch fare embarked class who
... ... ... ... ... ... ... ... ... ... ...
file:///C:/Users/goura/Downloads/16-Seaborn.html 20/100
2/15/25, 10:35 PM 16-Seaborn
In [23]: # faceting using col and row -> not work on histplot function
In [24]: # kdeplot
# Rather than using discrete bins, a KDE plot smooths the observations with a
# Gaussian kernel, producing a continuous density estimate
sns.kdeplot(data=tips,x='total_bill')
file:///C:/Users/goura/Downloads/16-Seaborn.html 21/100
2/15/25, 10:35 PM 16-Seaborn
In [25]: sns.displot(data=tips,x='total_bill',kind='kde')
file:///C:/Users/goura/Downloads/16-Seaborn.html 22/100
2/15/25, 10:35 PM 16-Seaborn
In [27]: # Rugplot
file:///C:/Users/goura/Downloads/16-Seaborn.html 23/100
2/15/25, 10:35 PM 16-Seaborn
sns.kdeplot(data=tips,x='total_bill')
sns.rugplot(data=tips,x='total_bill')
file:///C:/Users/goura/Downloads/16-Seaborn.html 24/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 25/100
2/15/25, 10:35 PM 16-Seaborn
2. Matrix Plot
Heatmap
Clustermap
In [31]: # Heatmap
file:///C:/Users/goura/Downloads/16-Seaborn.html 26/100
2/15/25, 10:35 PM 16-Seaborn
In [32]: # annot
temp_df = gap[gap['continent'] == 'Europe'].pivot(index='country',columns='year'
plt.figure(figsize=(15,15))
sns.heatmap(temp_df,annot=True,linewidth=0.5, cmap='summer')
file:///C:/Users/goura/Downloads/16-Seaborn.html 27/100
2/15/25, 10:35 PM 16-Seaborn
In [33]: # Clustermap
iris = px.data.iris()
iris
file:///C:/Users/goura/Downloads/16-Seaborn.html 28/100
2/15/25, 10:35 PM 16-Seaborn
In [34]: sns.clustermap(iris.iloc[:,[0,1,2,3]])
file:///C:/Users/goura/Downloads/16-Seaborn.html 29/100
2/15/25, 10:35 PM 16-Seaborn
TASK
In [35]: import pandas as pd
import numpy as np
plt.style.use("ggplot")
file:///C:/Users/goura/Downloads/16-Seaborn.html 30/100
2/15/25, 10:35 PM 16-Seaborn
Out[38]: index PatientID age gender bmi bloodpressure diabetic children smoker
file:///C:/Users/goura/Downloads/16-Seaborn.html 31/100
2/15/25, 10:35 PM 16-Seaborn
In [40]: plt.subplots(figsize=(12,8))
sns.scatterplot(data=temp_df, x='age', y='bmi', hue='diabetic',size='claim',
style='smoker')
plt.show()
file:///C:/Users/goura/Downloads/16-Seaborn.html 32/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 33/100
2/15/25, 10:35 PM 16-Seaborn
sns.clustermap(df[['age','bmi','bloodpressure']].dropna())
file:///C:/Users/goura/Downloads/16-Seaborn.html 34/100
2/15/25, 10:35 PM 16-Seaborn
In [45]: df.isnull().sum()
Out[45]: index 0
PatientID 0
age 5
gender 0
bmi 0
bloodpressure 0
diabetic 0
children 0
smoker 0
region 3
claim 0
dtype: int64
Categorical Plots
Categorical Scatter Plot
Stripplot
Swarmplot
file:///C:/Users/goura/Downloads/16-Seaborn.html 35/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 36/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 37/100
2/15/25, 10:35 PM 16-Seaborn
In [49]: # jitter
file:///C:/Users/goura/Downloads/16-Seaborn.html 38/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 39/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 40/100
2/15/25, 10:35 PM 16-Seaborn
In [52]: # hue
sns.swarmplot(data = tips, x = 'day', y = 'total_bill',hue = 'sex')
Boxplot
A boxplot is a standardized way of displaying the distribution of data based on a
five number summary (“minimum”, first quartile [Q1], median, third quartile [Q3]
and “maximum”). It can tell you about your outliers and what their values are.
Boxplots can also tell you if your data is symmetrical, how tightly your data is
grouped and if and how your data is skewed.
file:///C:/Users/goura/Downloads/16-Seaborn.html 41/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 42/100
2/15/25, 10:35 PM 16-Seaborn
In [55]: # Hue
file:///C:/Users/goura/Downloads/16-Seaborn.html 43/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 44/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 45/100
2/15/25, 10:35 PM 16-Seaborn
In [59]: # hue
file:///C:/Users/goura/Downloads/16-Seaborn.html 46/100
2/15/25, 10:35 PM 16-Seaborn
In [60]: # barplot
# some issue with errorbar
import numpy as np
sns.barplot(data = tips, x = 'sex', y = 'total_bill',hue = 'smoker',
estimator = np.mean)
file:///C:/Users/goura/Downloads/16-Seaborn.html 47/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 48/100
2/15/25, 10:35 PM 16-Seaborn
When there are multiple observations in each category, it also uses bootstrapping
to compute a confidence interval around the estimate, which is plotted using error
bars
In [63]: # countplot
file:///C:/Users/goura/Downloads/16-Seaborn.html 49/100
2/15/25, 10:35 PM 16-Seaborn
A special case for the bar plot is when you want to show the number of
observations in each category rather than computing a statistic for a second
variable. This is similar to a histogram over a categorical, rather than quantitative,
variable
file:///C:/Users/goura/Downloads/16-Seaborn.html 50/100
2/15/25, 10:35 PM 16-Seaborn
Regression Plots
regplot
lmplot
In the simplest invocation, both functions draw a scatterplot of two variables, x and
y, and then fit the regression model y ~ x and plot the resulting regression line and
a 95% confidence interval for that regression.
file:///C:/Users/goura/Downloads/16-Seaborn.html 51/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 52/100
2/15/25, 10:35 PM 16-Seaborn
In [68]: # residplot
file:///C:/Users/goura/Downloads/16-Seaborn.html 53/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 54/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 55/100
2/15/25, 10:35 PM 16-Seaborn
In [74]: print(iris.isnull().sum())
sepal_length 0
sepal_width 0
petal_length 0
petal_width 0
species 0
species_id 0
dtype: int64
sepal_length 0
sepal_width 0
petal_length 0
petal_width 0
species 0
species_id 0
dtype: int64
file:///C:/Users/goura/Downloads/16-Seaborn.html 56/100
2/15/25, 10:35 PM 16-Seaborn
In [76]: # vars
g = sns.PairGrid(data=iris,hue='species',vars=['sepal_width','petal_width'])
g.map_diag(sns.histplot)
g.map_upper(sns.kdeplot)
g.map_lower(sns.scatterplot)
file:///C:/Users/goura/Downloads/16-Seaborn.html 57/100
2/15/25, 10:35 PM 16-Seaborn
JointGrid Vs Jointplot
In [77]: sns.jointplot(data=tips,x='total_bill',y='tip',kind='hist',hue='sex')
file:///C:/Users/goura/Downloads/16-Seaborn.html 58/100
2/15/25, 10:35 PM 16-Seaborn
In [78]: g = sns.JointGrid(data=tips,x='total_bill',y='tip')
g.plot(sns.kdeplot,sns.violinplot)
file:///C:/Users/goura/Downloads/16-Seaborn.html 59/100
2/15/25, 10:35 PM 16-Seaborn
Utility Functions
In [79]: # get dataset names
sns.get_dataset_names()
file:///C:/Users/goura/Downloads/16-Seaborn.html 60/100
2/15/25, 10:35 PM 16-Seaborn
Out[79]: ['anagrams',
'anscombe',
'attention',
'brain_networks',
'car_crashes',
'diamonds',
'dots',
'dowjones',
'exercise',
'flights',
'fmri',
'geyser',
'glue',
'healthexp',
'iris',
'mpg',
'penguins',
'planets',
'seaice',
'taxis',
'tips',
'titanic',
'anagrams',
'anagrams',
'anscombe',
'anscombe',
'attention',
'attention',
'brain_networks',
'brain_networks',
'car_crashes',
'car_crashes',
'diamonds',
'diamonds',
'dots',
'dots',
'dowjones',
'dowjones',
'exercise',
'exercise',
'flights',
'flights',
'fmri',
'fmri',
'geyser',
'geyser',
'glue',
'glue',
'healthexp',
'healthexp',
'iris',
'iris',
'mpg',
'mpg',
'penguins',
'penguins',
'planets',
'planets',
'seaice',
'seaice',
file:///C:/Users/goura/Downloads/16-Seaborn.html 61/100
2/15/25, 10:35 PM 16-Seaborn
'taxis',
'taxis',
'tips',
'tips',
'titanic',
'titanic',
'anagrams',
'anscombe',
'attention',
'brain_networks',
'car_crashes',
'diamonds',
'dots',
'dowjones',
'exercise',
'flights',
'fmri',
'geyser',
'glue',
'healthexp',
'iris',
'mpg',
'penguins',
'planets',
'seaice',
'taxis',
'tips',
'titanic']
planets = pd.read_csv("https://raw.githubusercontent.com/mwaskom/seaborn-data/re
tips = sns.load_dataset('tips')
Themeing
set_theme
Set aspects of the visual theme for all matplotlib and seaborn plots.
axes_style
Get the parameters that control the general style of the plots.
set_style
Set the parameters that control the general style of the plots.
plotting_context
file:///C:/Users/goura/Downloads/16-Seaborn.html 62/100
2/15/25, 10:35 PM 16-Seaborn
set_context
set_color_codes
reset_defaults
reset_orig
set_theme function :
This function is used to set the theme of your plots, it can take a variety of
inputs such as 'darkgrid', 'whitegrid', 'dark', 'white' or 'ticks'.
Example:
In [83]: tips.head()
file:///C:/Users/goura/Downloads/16-Seaborn.html 63/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 64/100
2/15/25, 10:35 PM 16-Seaborn
axes_style function :
This function is used to set the style of the axes of your plots. It can take a variety of
inputs such as 'white', 'dark', 'ticks' or a dictionary with key-value pairs of valid style
options.
In [87]: # Example:
sns.axes_style(style = 'white')
sns.barplot(x=["A", "B", "C"], y=[1, 3, 2])
file:///C:/Users/goura/Downloads/16-Seaborn.html 65/100
2/15/25, 10:35 PM 16-Seaborn
In [88]: # Use the function as a context manager to temporarily change the style of your
# plots:
with sns.axes_style("white"):
sns.barplot(x=[1, 2, 3], y=[2, 5, 3])
In [89]: sns.get_data_home()
file:///C:/Users/goura/Downloads/16-Seaborn.html 66/100
2/15/25, 10:35 PM 16-Seaborn
Out[89]: 'C:\\Users\\goura\\AppData\\Local\\seaborn\\seaborn\\Cache'
file:///C:/Users/goura/Downloads/16-Seaborn.html 67/100
2/15/25, 10:35 PM 16-Seaborn
Scaling Plots
Seaborn has four presets which set the size of the plot and allow you to customize your
figure depending on how it will be presented.
In order of relative size they are: paper , notebook , talk , and poster . The
notebook style is the default.
In [92]: sns.set_style("ticks")
In [93]: sns.set_style("ticks")
file:///C:/Users/goura/Downloads/16-Seaborn.html 68/100
2/15/25, 10:35 PM 16-Seaborn
You may want to also change the line width so it matches. We do this with the rc
parameter, which we’ll explain in detail below.
In [94]: # Set font scale and reduce grid line width to match
sns.set_style("darkgrid")
file:///C:/Users/goura/Downloads/16-Seaborn.html 69/100
2/15/25, 10:35 PM 16-Seaborn
While you’re able to change these parameters, you should keep in mind
that it’s not always useful to make certain changes. Notice in this example
that we’ve changed the line width, but because of it’s relative size to the
plot, it distracts from the actual plotted data.
In [95]: # Set font scale and increase grid line width to match
sns.set_context("poster", font_scale = .8, rc={"grid.linewidth": 5})
sns.stripplot(x="day", y="total_bill", data=tips)
file:///C:/Users/goura/Downloads/16-Seaborn.html 70/100
2/15/25, 10:35 PM 16-Seaborn
The RC Parameter
As we mentioned above, if you want to override any of these standards, you can use
sns.set_context and pass in the parameter rc to target and reset the value of an
individual parameter in a dictionary. rc stands for the phrase ‘run command’ -
essentially, configurations which will execute when you run your code.
sns.plotting_context()
# These are the property you can tweak in rc parameter
file:///C:/Users/goura/Downloads/16-Seaborn.html 71/100
2/15/25, 10:35 PM 16-Seaborn
seaborn.set_color_codes(palette=’deep’)
Change how matplotlib color shorthands are interpreted.
Calling this will change how shorthand codes like “b” or “g” are interpreted by matplotlib
in subsequent plots.
Parameters:
file:///C:/Users/goura/Downloads/16-Seaborn.html 72/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 73/100
2/15/25, 10:35 PM 16-Seaborn
Color palettes
set_palette
color_palette
husl_palette
Return hues with constant lightness and saturation in the HUSL system.
hls_palette
Return hues with constant lightness and saturation in the HLS system.
cubehelix_palette
dark_palette
light_palette
file:///C:/Users/goura/Downloads/16-Seaborn.html 74/100
2/15/25, 10:35 PM 16-Seaborn
diverging_palette
blend_palette
xkcd_palette
Make a palette with color names from the xkcd color survey.
crayon_palette
mpl_palette
color_palette
https://seaborn.pydata.org/generated/seaborn.color_palette.html#seaborn.color_palette
In Seaborn, the color_palette() function allows you to easily specify the colors for
your plots. You can use pre-defined palettes, such as "deep", "muted", "pastel", "bright",
"dark", and "colorblind", or you can create your own custom palette.
When using a pre-defined palette, you can specify the number of colors you want to use
by passing in the desired number as the argument.
For example, using the "deep" palette and specifying 6 colors will return an array of 6
RGB color codes that can be used in your plot.
You can also create your own custom color palette by passing in a list of RGB color
codes.
file:///C:/Users/goura/Downloads/16-Seaborn.html 75/100
2/15/25, 10:35 PM 16-Seaborn
In [ ]:
file:///C:/Users/goura/Downloads/16-Seaborn.html 76/100
2/15/25, 10:35 PM 16-Seaborn
set_palette
The set_palette() function in seaborn allows you to specify a color palette for your
plots. This can be done by passing in one of the pre-defined seaborn palettes (such as
file:///C:/Users/goura/Downloads/16-Seaborn.html 77/100
2/15/25, 10:35 PM 16-Seaborn
"deep", "muted", "bright", etc.) or by passing in your own custom list of colors or
color_palette.
gap = px.data.gapminder()
gap.head()
You can also pass in a custom list of colors. For example, the following code would
set the palette to the colors red, blue, and green:
file:///C:/Users/goura/Downloads/16-Seaborn.html 78/100
2/15/25, 10:35 PM 16-Seaborn
You can also pass in a number of different arguments to set_palette. For example, the
following code sets the color palette to a specific hue, with 8 colors, and a desaturated
lightness:
file:///C:/Users/goura/Downloads/16-Seaborn.html 79/100
2/15/25, 10:35 PM 16-Seaborn
Now say we have set pallete colors and passed three colors, like we did above and want
to plot of 4 or more country line plots?
file:///C:/Users/goura/Downloads/16-Seaborn.html 80/100
2/15/25, 10:35 PM 16-Seaborn
See it took, color palette we set as - sns.set_palette("husl",8, .7), with eight colors. Even if
we are specifying set palette as ['red', 'blue', 'green']
# This will give right expected result as it has enough colors in the palette
# to show.
file:///C:/Users/goura/Downloads/16-Seaborn.html 81/100
2/15/25, 10:35 PM 16-Seaborn
seaborn.husl_palette
seaborn.husl_palette(n_colors=6, h=0.01, s=0.9, l=0.65, as_cmap=False)
Return hues with constant lightness and saturation in the HUSL system.
The hues are evenly sampled along a circular path. The resulting palette
will be appropriate for categorical or cyclical data.
Parameters:
We can also use 'husl' or 'hsl' parameter in set_palette function for the same. Like we did
in above example.
file:///C:/Users/goura/Downloads/16-Seaborn.html 82/100
2/15/25, 10:35 PM 16-Seaborn
cubehelix_palette
The seaborn.cubehelix_palette function is used to generate a colormap based on the
cubehelix color scheme, which is a sequential color map with a linear increase in
brightness and a smooth progression through the hues of the spectrum. This function
takes several optional parameters such as start , rot , gamma , light , dark ,
reverse and as_cmap to control the properties of the color palette.
For example, the following code generates a cubehelix color palette with 8 colors,
starting from a blue hue, and with increasing brightness and a rotation of 0.5:
This palette can be used to color various plotting elements such as bars, lines, and points
in a graph.
file:///C:/Users/goura/Downloads/16-Seaborn.html 83/100
2/15/25, 10:35 PM 16-Seaborn
In [122… sns.heatmap(iris.corr(numeric_only=True
), cmap=sns.cubehelix_palette(8, start=.5, rot=-.75,
gamma=.3, light=.9, dark=.1, as_cmap=True))
file:///C:/Users/goura/Downloads/16-Seaborn.html 84/100
2/15/25, 10:35 PM 16-Seaborn
TASK
In [123… import numpy as np
import pandas as pd
plt.style.use("ggplot")
In [ ]:
In [124… df = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/refs/he
In [125… print(df.shape)
df.head()
(53940, 10)
file:///C:/Users/goura/Downloads/16-Seaborn.html 85/100
2/15/25, 10:35 PM 16-Seaborn
In [126… sns.violinplot(data=df,x='cut',y='price')
In [127… sns.lmplot(data=df,x='carat',y='price',hue='cut')
file:///C:/Users/goura/Downloads/16-Seaborn.html 86/100
2/15/25, 10:35 PM 16-Seaborn
In [128… sns.lmplot(data=df,x='carat',y='price',col='cut',col_wrap=3)
In [129… sns.catplot(data=df,x='color',y='price',kind='box')
file:///C:/Users/goura/Downloads/16-Seaborn.html 87/100
2/15/25, 10:35 PM 16-Seaborn
In [133… df.head()
Out[133… pickup dropoff passengers distance fare tip tolls total color payment pi
2019- 2019-
credit
0 03-23 03-23 1 1.60 7.0 2.15 0.0 12.95 yellow
card
20:21:09 20:27:24
2019- 2019-
U
1 03-04 03-04 1 0.79 5.0 0.00 0.0 9.30 yellow cash
16:11:55 16:19:00
2019- 2019-
credit
2 03-27 03-27 1 1.37 7.5 2.36 0.0 14.16 yellow
card
17:53:01 18:00:25
2019- 2019-
credit
3 03-10 03-10 1 7.70 27.0 6.15 0.0 36.95 yellow
card
01:23:59 01:49:51
2019- 2019-
credit
4 03-30 03-30 3 2.16 9.0 1.10 0.0 13.40 yellow
card
13:27:42 13:37:14
In [134… sns.catplot(data=df,x='payment',y='total',kind='point')
file:///C:/Users/goura/Downloads/16-Seaborn.html 88/100
2/15/25, 10:35 PM 16-Seaborn
In [137… sns.lmplot(data=df,x='ride_time',y='total')
file:///C:/Users/goura/Downloads/16-Seaborn.html 89/100
2/15/25, 10:35 PM 16-Seaborn
In [138… sns.lmplot(data=df,x='ride_time',y='total',hue='color')
file:///C:/Users/goura/Downloads/16-Seaborn.html 90/100
2/15/25, 10:35 PM 16-Seaborn
In [139… sns.lmplot(data=df,x='ride_time',y='total',hue='payment')
file:///C:/Users/goura/Downloads/16-Seaborn.html 91/100
2/15/25, 10:35 PM 16-Seaborn
Out[140… index PatientID age gender bmi bloodpressure diabetic children smoker
In [141… sns.catplot(data=df,kind='strip',x='gender',y='bloodpressure',hue='smoker')
plt.title('BP Vs Gender vs Smoker')
In [142… sns.catplot(data=df,kind='swarm',x='gender',y='bloodpressure',hue='smoker')
plt.title('BP Vs Gender vs Smoker')
file:///C:/Users/goura/Downloads/16-Seaborn.html 92/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 93/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 94/100
2/15/25, 10:35 PM 16-Seaborn
sns.barplot(x='gender',y='claim',hue='smoker',data=df,ax=ax[0])
sns.pointplot(x='gender',y='claim',hue='smoker',data=df,ax=ax[1])
plt.show()
file:///C:/Users/goura/Downloads/16-Seaborn.html 95/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 96/100
2/15/25, 10:35 PM 16-Seaborn
g.map_diag(sns.boxplot)
g.map_upper(sns.scatterplot)
g.map_lower(sns.kdeplot)
file:///C:/Users/goura/Downloads/16-Seaborn.html 97/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 98/100
2/15/25, 10:35 PM 16-Seaborn
file:///C:/Users/goura/Downloads/16-Seaborn.html 99/100
2/15/25, 10:35 PM 16-Seaborn
In [ ]:
file:///C:/Users/goura/Downloads/16-Seaborn.html 100/100