14 Data Visualization Plots of Seaborn | by Aayush Ostwal | Towards Data Science

Data Visualization plays a very important role in Data mining. Various data scientist spent their time exploring data through visualization. To accelerate this process we need to have a well-documentation of all the plots.
Even plenty of resources can’t be transformed into valuable goods without planning and architecture. Therefore I hope this article would provide you a good architecture of all plots and their documentation.
IntroductionKnow your DataDistribution Plotsa. Dist-Plotb. Joint Plotc. Pair Plotd. Rug PlotCategorical Plotsa. Bar Plotb. Count Plotc. Box Plotd. Violin PlotAdvanced Plotsa. Strip Plotb. Swarm PlotMatrix Plotsa. Heat Mapb. Cluster MapGridsa. Facet GridRegression Plots
Introduction
Know your Data
Distribution Plotsa. Dist-Plotb. Joint Plotc. Pair Plotd. Rug Plot
Categorical Plotsa. Bar Plotb. Count Plotc. Box Plotd. Violin Plot
Advanced Plotsa. Strip Plotb. Swarm Plot
Matrix Plotsa. Heat Mapb. Cluster Map
Gridsa. Facet Grid
Regression Plots
Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics.
For the installation of Seaborn, you may run any of the following in your command line.
pip install seabornconda install seaborn
To import seaborn you can run the following command.
import seaborn as sns
The data set used in these plots is famous titanic data set (Fig. 1). Hereafter the data set is represented by the variable ‘df’.
These plots help us to visualize the distribution of data. We can use these plots to understand the mean, median, range, variance, deviation, etc of the data.
Dist plot gives us the histogram of the selected continuous variable.
It is an example of a univariate analysis.
We can change the number of bins i.e. number of vertical bars in a histogram
import seaborn as snssns.distplot(x = df['age'], bins = 10)
Here x-axis is the age and the y-axis displays frequency. For example, for bins = 10, there are around 50 people having age 0 to 10
It is the combination of the distplot of two variables.
It is an example of bivariate analysis.
We additionally obtain a scatter plot between the variable to reflecting their linear relationship. We can customize the scatter plot into a hexagonal plot, where, more the color intensity, the more will be the number of observations.
import seaborn as sns# For Plot 1sns.jointplot(x = df['age'], y = df['Fare'], kind = 'scatter')# For Plot 2sns.jointplot(x = df['age'], y = df['Fare'], kind = 'hex')
We can see that there no appropriate linear relation between age and fare.
kind = ‘hex’ provides the hexagonal plot and kind = ‘reg’ provides a regression line on the graph.
It takes all the numerical attributes of the data and plot pairwise scatter plot for two different variables and histograms from the same variables.
import seaborn as snssns.pairplot(df)
It draws a dash mark instead of a uniform distribution as in distplot.
It is an example of a univariate analysis.
import seaborn as snssns.rugplot(x = df['Age'])
These plots help us understand the categorical variables. We can use them for both univariate and bivariate analysis.
It is an example of bivariate analysis.
On the x-axis, we have a categorical variable and on the y-axis, we have a continuous variable.
import seaborn as snssns.barplot(x = df['Sex'], y = df['Fare'])
We can infer that the average fare is higher for females than males.
It counts the number of occurrences of categorical variables.
It is an example of a univariate analysis.
import seaborn as snssns.countplot(df['Pclass'])
It is a 5 point summary plot. It gives the information about the maximum, minimum, mean, first quartile, and third quartile of a continuous variable. Also, it equips us with knowledge of outliers.
We can plot this for a single continuous variable or can analyze different categorical variables based on a continuous variable.
import seaborn as sns#For plot 1sns.countplot(df['Pclass'])#For plot 2sns.boxplot(y = df['Age'], x = df['Sex'])
It is similar to the Box plot, but it gives supplementary information about the distribution too.
import seaborn as snssns.violinplot(y = df['Age'], x = df['Sex'])
As the name suggests, they are advanced because they ought to fuse the distribution and categorical encodings.
It’s a plot between a continuous variable and a categorical variable.
It plots as a scatter plot but supplementarily uses categorical encodings of the categorical variable.
import seaborn as snssns.stripplot(y = df['Age'], x = df['Pclass'])
We can observe that in class 1 and class 2, children around 10 years are not present and the people having age above 60 are mostly accommodated in class 1.
Usually, these types of observations are used to impute missing values.
It is the combination of a strip plot and a violin plot.
Along with the number of data points, it also provides their respective distribution.
import seaborn as snssns.swarmplot(y = train['Age'], x = train['Pclass'])
These are the special types of plots that use two-dimensional matrix data for visualization. It is difficult to analyze and generate patterns from matrix data because of its large dimensions. So, this makes the process easier by providing color coding to matrix data.
In the given raw dataset ‘df’, we have seven numeric variables. So, let us generate a correlation matrix between these seven variables.
df.corr()
It seems very difficult to read every value even though there are only 49 values. The intricacy intensifies as we traverse towards thousands of features.So, let us try to implement some color coding and see how easy the interpretation becomes.
sns.heatmap(df.corr(), annot = True, cmap = 'viridis')
The same matrix is now articulating more information.
Another very obvious example is to use heatmaps to understand the missing value patterns. In Fig. 14, the yellow dash represents a missing value, hence it makes our tasks more effortless to identify the missing values.
sns.heatmap(df.isnull(),yticklabels=False,cbar=False,cmap='viridis')
If we have a matrix data and want to group some features according to their similarity, cluster maps can assist us. Once, have a look at the heat map (Fig. 13) and then look at the cluster map (Fig. 15).
sns.clustermap(tran.corr(), annot='True',cmap='viridis')
The x-label and y-label are the same but they harmonized differently. That is because they are grouped according to their similarity.
The flow-chart like structure at the top and left describe their degree of similarity.
Cluster maps use Hierarchical clustering to form different clusters.
Grid plots provide us more control over visualizations and plots various assorted graphs with a single line of code.
Suppose we want to plot the age distribution of males and females in all the three classes of tickets. Hence, we would be having in a total of 6 graphs.
sns.FacetGrid(train, col = 'Pclass', row = 'Sex').map(sns.distplot, 'Age')
The Facet grids provide very clear graphs as per requirements.
sns.FacetGrid( col = ‘col’, row = ‘row’, data = data) provides an empty grid of all unique categories in the col and row. Later, we can use different plots and common variables for peculiar variations.
This is a more advanced statistical plot that provides a scatter plot along with a linear fitting on the data.
sns.lmplot(x = 'Age', y = 'PassengerId', data = df, hue = 'Sex)
Fig. 17 displays the linear regression fitting between Passenger ID and Age for both males and females.
In this article, we have seen 14 different visualization techniques using seaborn.
I believe data visualization enhances our understanding and potential for interpreting data. It gives us more satisfying skills to represent data, impute missing values, identify outliers, detect anomalies, and a lot more.
Data Analysts are like cops that need to interrogate data and extract information via them. It is extremely necessary to have optimistic tools to do the job. Therefore, I hope this article would serve you as a tool for interrogating your data.
For the Guide for Exploratory data analysis, visit-
towardsdatascience.com
For such content related to data science, machine learning, programming, please visit y youtube channel.