Visualization with Seaborn

Ankit Gupta
3 min readDec 26, 2021

Seaborn is a python library for generating statistical graphs. It is build on top of matplotlib and integrates closely with pandas. It helps us in data exploration and understanding its distribution.

Sample of Titanic Data

Count Plot : A count plot is similar to histogram or a bar plot. It shows the number of occurrences of an item based on a certain type of category. It can be thought of as a histogram across a categorical, rather than quantitative, variable.

#importing library
import seaborn as sns
#setting theme
sns.set_theme(style="darkgrid")
#importing dataset
titanic = sns.load_dataset("titanic")
#plotting chart
ax = sns.countplot(x="class", data=titanic, hue="sex", palette="Blues")
plt.show()
Count Plot using Seaborn For Titanic Dataset

Histogram : It a graphical representation that organizes a group of data points into user-specified buckets or ranges.

#importing library
import seaborn as sns
#setting theme
sns.set_theme(style="darkgrid")
#importing dataset
titanic = sns.load_dataset("titanic")
#plotting chart
sns.histplot(data=titanic, x="age", kde=True, bins = 5, hue = 'sex')
plt.show()
Histogram using Seaborn for Titanic Dataset

Box Plot : It displays the five-number summary of a set of data i.e. the minimum, first quartile, median, third quartile, and maximum.

#importing library
import seaborn as sns
#setting theme
sns.set_theme(style="darkgrid")
#importing dataset
titanic = sns.load_dataset("titanic")
#plotting chart
sns.boxplot(data=titanic, x="class", y='age', hue ='sex', palette="Greens")
plt.show()
Boxplot using Seaborn for Titanic Dataset

Scatter Plot : A scatter plot uses Cartesian coordinates to display relationship for two variables for a set of data.

#importing library
import seaborn as sns
#setting theme
sns.set_theme(style="darkgrid")
#importing dataset
titanic = sns.load_dataset("titanic")
#plotting chart
sns.scatterplot(data=titanic, x="age", y='fare', hue ='alive', palette="Greens")
plt.show()
Scatter Plot for Titanic Dataset

Joint Plot : It comprises three plots. One bivariate graph showing two variables, and two univariate graphs for each of the variables individually. Below chart will make it more clear.

#importing library
import seaborn as sns
#setting theme
sns.set_theme(style="darkgrid")
#importing dataset
titanic = sns.load_dataset("titanic")
#plotting chart
sns.jointplot(data=titanic, x="age", y='fare', hue ='alive', palette="Greens")
plt.show()
Joint Plot For Titanic Dataset

We can also add a linear regression fit to the joint plot by adding value to “kind” parameter.

#importing library
import seaborn as sns
#setting theme
sns.set_theme(style="darkgrid")
#importing dataset
titanic = sns.load_dataset("titanic")
#plotting chart
sns.jointplot(data=titanic, x="age", y='fare', palette="Greens", kind = "reg")
plt.show()
Adding Regression Line Fit to Joint Plot

Pair Plot : It is useful in plotting pairwise relationships in a dataset.

#importing library
import seaborn as sns
#setting theme
sns.set_theme(style="darkgrid")
#importing dataset
titanic = sns.load_dataset("titanic")
#plotting chart
sns.pairplot(titanic, hue="alive")
plt.show()
Pairwise Plot for Titanic Dataset

--

--