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.

 

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.

 

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

 

 

Similar Reads

Getting Started

First of all, let us install Seaborn. Seaborn can be installed using the pip. Type the below command in the terminal....

Using Seaborn with Matplotlib

...

Customizing Seaborn Plots

Using both Matplotlib and Seaborn together is a very simple process. We just have to invoke the Seaborn Plotting function as normal, and then we can use Matplotlib’s customization function....

Color Palette

...

Multiple plots with Seaborn

...

Creating Different Types of Plots

Seaborn comes with some customized themes and a high-level interface for customizing the looks of the graphs. Consider the above example where the default of the Seaborn is used. It still looks nice and pretty but we can customize the graph according to our own needs. So let’s see the styling of plots in detail....

Relational Plots

...

Categorical Plots

...

Distribution Plots

...

Regression Plots

...

More Gaphs in Seaborn

...

More Topics on Seaborn

Colormaps are used to visualize plots effectively and easily. One might use different sorts of colormaps for different kinds of plots. color_palette() method is used to give colors to the plot. Another function palplot() is used to deal with the color palettes and plots the color palette as a horizontal array....