Seaborn Tutorial
Distribution Plot
1. Distplot
2. Joinplot
3. Pairplot
In [8]:
import seaborn as sns
import numpy as np
import pandas as pd
import matplotlib as plt
In [9]:
df= pd.read_csv('C:/Users/anirb/OneDrive/Documents/Spotify project/SpotifyFeatures.csv')
In [10]:
df.head()
Out[10]: genre artist_name track_name track_id popularity acousticness danceability duration_ms
C'est beau
Henri
0 Movie de faire un 0BRjO6ga9RKCKjfDqeFgWV 0 0.611 0.389 99373
Salvador
Show
Perdu
Martin & les d'avance
1 Movie 0BjC1NfoEOOusryehmNudP 1 0.246 0.590 137373
fées (par Gad
Elmaleh)
Don't Let
Joseph Me Be
2 Movie 0CoSDzoNIKCRs124s9uTVy 3 0.952 0.663 170267
Williams Lonely
Tonight
Dis-moi
Henri Monsieur
3 Movie 0Gc6TVm52BwZD07Ki6tIvf 0 0.703 0.240 152427
Salvador Gordon
Cooper
Fabien
4 Movie Ouverture 0IuslXpMROHdEPvSl1fTQK 4 0.950 0.331 82625
Nataf
Correlation with Heatmap
A correlation heapmap used to color cells and show a 2D correlation matrix between discrete dimenssions or
event types.
In [11]:
df.corr()
Out[11]: popularity acousticness danceability duration_ms energy instrumentalness liveness lou
popularity 1.000000 -0.381295 0.256564 0.002348 0.248922 -0.210983 -0.167995 0.3
acousticness -0.381295 1.000000 -0.364546 0.011203 -0.725576 0.316154 0.069004 -0.6
danceability 0.256564 -0.364546 1.000000 -0.125781 0.325807 -0.364941 -0.041684 0.4
Loading [MathJax]/extensions/Safe.js
popularity acousticness danceability duration_ms energy instrumentalness liveness lou
duration_ms 0.002348 0.011203 -0.125781 1.000000 -0.030550 0.076021 0.023783 -0.0
energy 0.248922 -0.725576 0.325807 -0.030550 1.000000 -0.378957 0.192801 0.8
instrumentalness -0.210983 0.316154 -0.364941 0.076021 -0.378957 1.000000 -0.134198 -0.5
liveness -0.167995 0.069004 -0.041684 0.023783 0.192801 -0.134198 1.000000 0.0
loudness 0.363011 -0.690202 0.438668 -0.047618 0.816088 -0.506320 0.045686 1.0
speechiness -0.151076 0.150935 0.134560 -0.016171 0.145120 -0.177147 0.510147 -0.0
tempo 0.081039 -0.238247 0.021939 -0.028456 0.228774 -0.104133 -0.051355 0.2
valence 0.060076 -0.325798 0.547154 -0.141811 0.436771 -0.307522 0.011804 0.3
In [13]:
sns.heatmap(df.corr())
Out[13]: <AxesSubplot:>
Joint Plot
A jointplot allows to study the relationship between 2 numeric variables.the central chart represent their
corelation.It is usually a scatter plot ,a hexbin plot, a 2D histogram or a density plot.
In [14]:
sns.jointplot(x='instrumentalness',y='loudness',data= df,kind= 'hex')
Out[14]: <seaborn.axisgrid.JointGrid at 0x1c30abe59d0>
Loading [MathJax]/extensions/Safe.js
In [16]:
sns.jointplot(x='popularity',y='acousticness',data= df,kind= 'hex')
Out[16]: <seaborn.axisgrid.JointGrid at 0x1c30f348a90>
In [17]:
sns.jointplot(x='popularity',y='acousticness',data= df,kind= 'reg')
Out[17]: <seaborn.axisgrid.JointGrid at 0x1c30f9b3970>
Loading [MathJax]/extensions/Safe.js
Pairplot
If we want to show more than one feature comparing with other variable then we use Pairplot.It is also known as
scatterplot.
In [20]:
sns.pairplot(df)
Out[20]: <seaborn.axisgrid.PairGrid at 0x1c32032a9a0>
Loading [MathJax]/extensions/Safe.js
Loading [MathJax]/extensions/Safe.js