Grid Plot in Python using Seaborn
Last Updated :
22 Jun, 2020
Grids are general types of plots that allow you to map plot types to grid rows and columns, which helps you to create similar character-separated plots. In this article, we will be using two different data sets (Iris and Tips) for demonstrating grid plots
Using Iris Dataset
We are going to use the Iris dataset which is a very famous dataset available as an in-built dataset. It contains a measurement of a bunch of different Irises(flowers). The dataset comprises of four measures: sepal distance, sepal weight, petal length, and petal width. We will be using the following code snippet for all the examples used below.
Code Snippet:
Python3
import seaborn as sns
import matplotlib.pyplot as plt
iris = sns.load_dataset( "iris" )
iris.head()
|
Output:

Note: Place the below code snippets at the place of the YOUR CODE HERE.
Pair Plot
Pair Plot is like an automated joint plot for the entire dataset. In a sample, a pair plot maps a pairwise partnership. The pairplot()
method generates an Axes map, such that each data vector is spread over a single row in the y-axis and across a single column in the x-axis. That generates plots as shown below.
sns.pairplot(data = iris)

We use ‘hue’ to visualize independent color for each type of ‘species’ in the plot. And the palette is used for customizing colors of the plot as shown below.
sns.pairplot(iris, hue="species", palette="rainbow")

Pair Grid
We can customize pair plot by using seaborn’s PairGrid mechanism. PairGrid takes all the numerical columns and grids them up making subplots as shown below.
sns.PairGrid(data = iris)

We can map to the grid by calling ‘.map’ off of it. Over here we have called the scatter plot by ‘.scatter’. Now all the grids will be of scatter plot kind. We can define the type of plot we want in the grids using the ‘.map’.
g = sns.PairGrid(iris)
g.map(plt.scatter) #All the grids plot scatter plot

To map into the upper grid, lower grid and diagonal grid we call ‘.map_upper’, ‘.map_lower’, ‘.map_diag’ off of the PairGrid. Over here we can see the diagonals are ‘hist’ type plot, the upper grid is’scatter’ type plot and the lower grid is ‘kde’ type plot.
g = sns.PairGrid(iris)
g.map_diag(plt.hist)
g.map_upper(plt.scatter)
g.map_lower(sns.kdeplot)

Using Tips Dataset
We are going to use another in-built dataset. The dataset comprises of seven features: total bill, tip, sex, smoker, day, time, size. We will be using the following code snippet for all the examples used below.
Code Snippet:
Python3
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset( "tips" )
tips.head()
|
Output:

Note: Place the below code snippets at the place of the YOUR CODE HERE.
FacetGrid
FacetGrid is a general way of creating plot grids based on a function. Its object uses the dataframe as input and the names of the variables that shape the row, column, or color dimensions of the grid.
Over here we can see, as there are two types of values in the smoker column which is smoker = No and smoker = Yes so this creates two rows in grid one for smoker = Yes and other for smoker = No. For the columns, as there are two types of values in time column which is time = Lunch and time = Dinner so this creates two columns in grid one for time = Lunch and other for time = Dinner.
g = sns.FacetGrid(tips, col="time", row="smoker")

The total bills are plotted as hist across the grid we created using’map’.
g = sns.FacetGrid(tips, col="time", row="smoker")
g = g.map(plt.hist, "total_bill")

Over here we have defined hue as sex and also plotted a scatter plot where X-axis is total_bill and Y-axis is yip..
g = sns.FacetGrid(tips, col="time", row="smoker", hue='sex')
g = g.map(plt.scatter, "total_bill", "tip").add_legend()

Joint Grid
JointGrid is the general version for the grid type of jointplot()
. Jointplot by Seaborn shows a relationship in the margins between 2 variables (bivariate) and 1D profiles (univariate). This plot is a product form that wraps up the JointGrid.
g = sns.JointGrid(x="total_bill", y="tip", data=tips)

g = sns.JointGrid(x="total_bill", y="tip", data=tips)
g = g.plot(sns.regplot, sns.distplot)

Similar Reads
Lineplot using Seaborn in Python
Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides default styles and color palettes to make statistical plots more attractive. It is built on the top of the matplotlib library and is also closely integrated into the data structures from pandas. Line
4 min read
Plotting graph using Seaborn | Python
This article will introduce you to graphing in Python with Seaborn, which is the most popular statistical visualization library in Python. Installation: The easiest way to install seaborn is to use pip. Type following command in terminal: pip install seaborn OR, you can download it from here and ins
8 min read
Barplot using seaborn in Python
Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides beautiful default styles and color palettes to make statistical plots more attractive. It is built on the top of matplotlib library and also closely integrated to the data structures from pandas. Sea
6 min read
Boxplot using Seaborn in Python
Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides beautiful default styles and color palettes to make statistical plots more attractive. It is built on the top of matplotlib library and also closely integrated into the data structures from pandas. B
5 min read
Python - seaborn.pointplot() method
Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides beautiful default styles and color palettes to make statistical plots more attractive. It is built on the top of matplotlib library and also closely integrated to the data structures from pandas. sea
3 min read
Plotting Numpy Array Using Seaborn
Seaborn, a powerful Python data visualization library built on top of matplotlib, provides a range of tools for creating informative and attractive statistical graphics. One of its key features is the ability to plot numpy arrays, which are fundamental data structures in Python. This article delves
4 min read
Multi-plot grid in Seaborn
Prerequisites: Matplotlib, Seaborn In this article, we are going to see multi-dimensional plot data, It is a useful approach to draw multiple instances of the same plot on different subsets of your dataset. It allows a viewer to quickly extract a large amount of information about a complex dataset.
6 min read
Splitting Violin Plots in Python Using Seaborn
A violin plot is a data visualization technique that combines aspects of a box plot and a kernel density plot. It is particularly useful for visualizing the distribution of data across different categories. Sometimes, it can be helpful to split each violin in a violin plot to compare two halves of t
5 min read
Stripplot using Seaborn in Python
Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides beautiful default styles and color palettes to make statistical plots more attractive. It is built on top of the matplotlib library and also closely integrated into the data structures from pandas. S
5 min read
seaborn.lineplot() method in Python
Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. The colors stand out, the layers blend nicely together, the contours flow throughout, and the overall package not only has a nice aesthe
2 min read