Python - seaborn.FacetGrid() Method

Introduction:

In this tutorial we are learning about the seaborn.FacetGrid() method in Python. The Seaborn is a Python data visualization library based on matplotlib. This library provides a high-level interface for attractive graphs and statistical data. Seaborn helps solve two major problems which are faced in Matplotlib. The problems are -

  1. Default parameters in Matplotlib,
  2. Working with the Data Frames.

Since Seaborn has added and extended Matplotlib, the learning curve has been very gradual. If you know Matplotlib, you already know half of Seaborn.

What is seaborn.FacetGrid() Method in Python?

The FacetGrid class facilitates the use of multiple variables to visualize the distribution of variables in a dataset and the relationships between variables. The FacetGrid draw in up to three dimensions which are row, col, and hue. The first two have explicit communication with the axis array values. Think of different levels as the third dimension of the depth axis, the difference between different colours. The FacetGrid object uses a dataframe as input and a grid of variable names that will form rows, columns, or hue dimensions. Variables must be categorical, and data from each level of the variable will be used for the variable axis.

The syntax of the seaborn.FacetGrid() method in Python is given below -

Seaborn.FacetGrid uses many arguments as input. The main parameters are described in tabular form as follows:

SL. No.ArgumentsValueDescription
1row, col, hueStringVariables that define subsets of data to be plotted on various grids. To control the hierarchical order of this variable, see the "*_order" parameter.
2palettelist, or dict, palette name, optionalThe colours used for "hue" are different at different levels.
3dataDataFrameTidy (long-form) dataframe where each row is an observation, and each column is a variable.

Program Code 1:

Here we give a program code of seaborn.FacetGrid() method in Python. The code is given below -

Output:

In the above code, we just instantiated the facetgrid object and it did not draw anything on it. The main way to display data in this grid is to use the FacetGrid.map() method. Now, we run the above code and find the output. The output is given below -

Python - seaborn.FacetGrid() Method

Program Code 2:

Here we give another program code of seaborn.FacetGrid() method in Python. The code is given below -

Output:

Now, we run the above code and find the output. The output is given below -

Python - seaborn.FacetGrid() Method

Program Code 3:

Here we give another program code of seaborn.FacetGrid() method in Python. The code is given below -

Output:

Now, we run the above code and find the output. There are multiple graphs due to the Col parameter. The output is given below -

Python - seaborn.FacetGrid() Method

Program Code 4:

Here we give another program code of seaborn.FacetGrid() method in Python. The code is given below -

Output:

Now, we run the above code and find the output. The output is given below -

Python - seaborn.FacetGrid() Method

Program Code 5:

Here we give another program code of seaborn.FacetGrid() method in Python. The code is given below -

Output:

Now, we run the above code and find the output. The output is given below -

Python - seaborn.FacetGrid() Method

Program Code 6:

Here we give another program code of seaborn.FacetGrid() method in Python. The code is given below -

Output:

Now, we run the above code and find the output. The output is given below -

Python - seaborn.FacetGrid() Method