Categorical Plots
Categorical Plots are used where we have to visualize relationship between two numerical values. A more specialized approach can be used if one of the main variable is categorical which means such variables that take on a fixed and limited number of possible values.
Refer to the below articles to get detailed information.
There are various types of categorical plots let’s discuss each one them in detail.
Bar Plot
A barplot is basically used to aggregate the categorical data according to some methods and by default its the mean. It can also be understood as a visualization of the group by action. To use this plot we choose a categorical column for the x axis and a numerical column for the y axis and we see that it creates a plot taking a mean per categorical column. It can be created using the barplot() method.
Syntax:
barplot([x, y, hue, data, order, hue_order, …])
Example:
Python3
# importing packages import seaborn as sns import matplotlib.pyplot as plt # loading dataset data = sns.load_dataset( "iris" ) sns.barplot(x = 'species' , y = 'sepal_length' , data = data) plt.show() |
Output:
Refer to the below article to get detailed information about the topic.
Count Plot
A countplot basically counts the categories and returns a count of their occurrences. It is one of the most simple plots provided by the seaborn library. It can be created using the countplot() method.
Syntax:
countplot([x, y, hue, data, order, …])
Example:
Python3
# importing packages import seaborn as sns import matplotlib.pyplot as plt # loading dataset data = sns.load_dataset( "iris" ) sns.countplot(x = 'species' , data = data) plt.show() |
Output:
Refer to the below articles t get detailed information about the count plot.
Box Plot
A boxplot is sometimes known as the box and whisker plot.It shows the distribution of the quantitative data that represents the comparisons between variables. boxplot shows the quartiles of the dataset while the whiskers extend to show the rest of the distribution i.e. the dots indicating the presence of outliers. It is created using the boxplot() method.
Syntax:
boxplot([x, y, hue, data, order, hue_order, …])
Example:
Python3
# importing packages import seaborn as sns import matplotlib.pyplot as plt # loading dataset data = sns.load_dataset( "iris" ) sns.boxplot(x = 'species' , y = 'sepal_width' , data = data) plt.show() |
Output:
Refer to the below articles to get detailed information about box plot.
- Boxplot using Seaborn in Python
- Horizontal Boxplots with Seaborn in Python
- How To Use Seaborn Color Palette to Color Boxplot?
- Seaborn – Coloring Boxplots with Palettes
- How to Show Mean on Boxplot using Seaborn in Python?
- Sort Boxplot by Mean with Seaborn in Python
- How To Manually Order Boxplot in Seaborn?
- Grouped Boxplots in Python with Seaborn
- Horizontal Boxplots with Points using Seaborn in Python
- How to Make Boxplots with Data Points using Seaborn in Python?
- Box plot visualization with Pandas and Seaborn
Violinplot
It is similar to the boxplot except that it provides a higher, more advanced visualization and uses the kernel density estimation to give a better description about the data distribution. It is created using the violinplot() method.
Syntax:
violinplot([x, y, hue, data, order, …]
Example:
Python3
# importing packages import seaborn as sns import matplotlib.pyplot as plt # loading dataset data = sns.load_dataset( "iris" ) sns.violinplot(x = 'species' , y = 'sepal_width' , data = data) plt.show() |
Output:
Refer to the below articles to get detailed information about violin plot.
- Violinplot using Seaborn in Python
- How to Make Horizontal Violin Plot with Seaborn in Python?
- Make Violinplot with data points using Seaborn
- How To Make Violinpot with data points in Seaborn?
- How to Make Grouped Violinplot with Seaborn in Python?
Stripplot
It basically creates a scatter plot based on the category. It is created using the stripplot() method.
Syntax:
stripplot([x, y, hue, data, order, …])
Example:
Python3
# importing packages import seaborn as sns import matplotlib.pyplot as plt # loading dataset data = sns.load_dataset( "iris" ) sns.stripplot(x = 'species' , y = 'sepal_width' , data = data) plt.show() |
Output:
Refer to the below articles to detailed information about strip plot.
Swarmplot
Swarmplot is very similar to the stripplot except the fact that the points are adjusted so that they do not overlap.Some people also like combining the idea of a violin plot and a stripplot to form this plot. One drawback to using swarmplot is that sometimes they dont scale well to really large numbers and takes a lot of computation to arrange them. So in case we want to visualize a swarmplot properly we can plot it on top of a violinplot. It is plotted using the swarmplot() method.
Syntax:
swarmplot([x, y, hue, data, order, …])
Example:
Python3
# importing packages import seaborn as sns import matplotlib.pyplot as plt # loading dataset data = sns.load_dataset( "iris" ) sns.swarmplot(x = 'species' , y = 'sepal_width' , data = data) plt.show() |
Output:
Refer to the below articles to get detailed information about swarmplot.
Factorplot
Factorplot is the most general of all these plots and provides a parameter called kind to choose the kind of plot we want thus saving us from the trouble of writing these plots separately. The kind parameter can be bar, violin, swarm etc. It is plotted using the factorplot() method.
Syntax:
sns.factorplot([x, y, hue, data, row, col, …])
Example:
Python3
# importing packages import seaborn as sns import matplotlib.pyplot as plt # loading dataset data = sns.load_dataset( "iris" ) sns.factorplot(x = 'species' , y = 'sepal_width' , data = data) plt.show() |
Refer to the below articles to get detailed information about the factor plot.
Python Seaborn Tutorial
Seaborn is a library mostly used for statistical plotting in Python. It is built on top of Matplotlib and provides beautiful default styles and color palettes to make statistical plots more attractive.
In this tutorial, we will learn about Python Seaborn from basics to advance using a huge dataset of seaborn basics, concepts, and different graphs that can be plotted.
Table Of Content
- Getting Started
- Using Seaborn with Matplotlib
- Customizing Seaborn Plots
- Changing Figure Aesthetic
- Removal of Spines
- Changing the figure Size
- Scaling the plots
- Setting the Style Temporarily
- Color Palette
- Diverging Color Palette
- Sequential Color Palette
- Setting the default Color Palette
- Multiple plots with Seaborn
- Using Matplotlib
- Using Seaborn
- Creating Different Types of Plots
- Relational Plots
- Categorical Plots
- Distribution Plots
- Regression Plots
- More Gaphs in Seaborn
- More Topics on Seaborn