Seaborn Matrix Plots - Introduction



A plot of matrix data is called a matrix plot. A matrix plot is a color-coded figure with values, data in the rows, and data in the columns. You can create matrix plots in seaborn by using either heatmap() or clustermap() functions.

Heatmap() is used to produce rectangular data as a color-coded matrix and Clustermap() is used to plot a dataset as a hierarchically clustered heat map.

To plot any data into a map, we need to import the data. You can either use datasets available in the seaborn library or import them as per your choice from elsewhere.

In-built datasets in Seaborn library

Seaborn contains various default datasets in addition to being a statistical charting toolkit. We'll use the one of the in-built datasets as an example of a default dataset.

Let us consider the tips dataset in the first example. The 'tips' dataset comprises information about people who have likely eaten at a restaurant and whether or not they left a tip for the servers, as well as their gender, smoking status, and other factors.

The Seaborn.get_dataset_names() method helps to retrieve all the names of the in-built datasets.

seaborn.get_dataset_names() 
>> ['anagrams', 'anscombe', 'attention', 'brain_networks', 'car_crashes', 'diamonds', 'dots', 'exercise', 'flights', 'fmri', 'gammas', 'geyser', 'iris', 'mpg', 'penguins', 'planets', 'taxis', 'tips', 'titanic']

From the above list, we will for now, use the tips dataset. To load the dataset into a data frame for use, the following method can be used.

load_dataset() method helps to load the dataset with the name into a data structure.

Tips=seaborn.load_dataset('tips')

The above line of code helps to load the dataset with the name 'tips' into a data structure called tips.

Now that we understand how to load an existing dataset, we will move on to understanding the working of the matrix plots.

S.No Method and Description
1 Heatmap()

Produces rectangular data as a color-coded matrix.

2 Clustermap()

Plots a dataset as a hierarchically clustered heat map.

The matrix plots, heatmap() and clustermap() are discussed in the coming articles.

seaborn_function_reference.htm
Advertisements