Here I will show you some of the important and nice plots in seaborn Python library:
- install the library using
pip install seaborn
- Numerical Values:
- Distplot
- Jointplot
- Correlation
- Pairplot
- Categorical values:
- Countplot
- "deep", "muted", "bright", "pastel", "dark",”rainbow”
- Barplot
- Boxplot
- Violinplot
import numpy as np
import pandas as pd
import seaborn as sns
df = sns.load_dataset("tips")
sns.displot(x='total_bill',data=df)
you can filter this distribution by sex, day, smoker etc
sns.displot(x='total_bill',hue='sex',data=df)
A join plot allows to study the relationship between 2 numeric variables. The central chart display their correlation. It is usually a scatterplot, a hex bin plot, a 2D histogram or a 2D density plot
sns.jointplot(x='tip',y='total_bill',data=df,kind="reg")
# Another way to plot it in hex
# sns.jointplot(x='tip',y='total_bill',data=df,kind="hex")
A correlation heatmap uses colored cells, typically in a monochromatic scale, to show a 2D correlation matrix (table) between two discrete dimensions or event types. It is very important in Feature Selection →can only be for Numerical values
# select the numerical columns from df
corr=df.select_dtypes(include=np.number).corr()
sns.heatmap(corr)
A "pairs plot" is also known as a scatterplot, in which one variable in the same data row is matched with another variable's value, like this: Pairs plots are just elaborations on this, showing all variables paired with all the other variables.
sns.pairplot(df)
A countplot is a type of plot used in data visualization that shows the count of observations in each category of a categorical variable. You need to give just one variable as x.
You can use the following color palettes
in seaborn
:
# This is the updated way
sns.countplot(x="day",hue='day',data=df,palette='muted')
# old way
sns.countplot(x="day",data=df,palette='husl')
A barplot is a type of data visualization that displays categorical data using rectangular bars. The length of each bar represents the frequency or value of the corresponding category. You have to give the x and y of the plot.
sns.barplot(y="total_bill",hue="sex",data=df,palette='muted')
A box and whisker plot (sometimes called a boxplot) is a graph that presents information from a five-number summary.
sns.boxplot (x='sex', y='total_bill', data=df,palette='muted')
sns.boxplot (x='tip', y='day',hue="sex", data=df,palette='muted')
Violin plot helps us to see both the distribution of data in terms of Kernel density estimation and the box plot
sns.violinplot(x='total_bill',hue='day',data=df,palette='muted')