Relplot in Seaborn

Ravjot Singh
The Startup
Published in
4 min readMay 6, 2020

--

Visualizing statistical relationships

Statistical analysis is a process of understanding how variables in a dataset relate to each other and how those relationships depend on other variables. Visualization can be a core component of this process because, when data are visualized properly, the human visual system can see trends and patterns that indicate a relationship.

In this article, we will discuss about the relplot() function of Seaborn library. This is a figure-level function for visualizing statistical relationships using two common approaches: scatter plots and line plots.

Scatter Plots- Each plot point is an independent observation

Line Plots- Each plot point represents the same “thing” , typically tracked over time

relplot() function of Seaborn

Why use relplot() instead of scatterplot() ?

Because relplot() lets you create subplots in a single feature.

Let’s start plotting using Seaborn

1. Importing the required libraries

2. Loading and Reading the dataset

We have loaded the dataset using pandas library.

Exploratory Data Analysis

3. Visualization Part

  1. SCATTER PLOTS-

Creating scatter plot with relplot() function of Seaborn library. Passing “kind” parameter equals to “scatter” will create scatter plot. Also, passing data , x and y inputs as the parameters.

Subplots in Columns:

Passing the “col” parameter in the function to create subplots in columns.

Subplots in columns

Subplots in Rows:

Passing the “row” parameter in the function to create subplots in rows.

Subplots in rows

Ordering Columns:

Changing the order of columns in subplots by passing the order in the “col_order” parameter.

Changing the order of columns in subplots

Ordering rows and columns:

Changing the order of both the rows and columns by passing order of columns and rows in “col_order” and “row_order” parameters.

Loading another dataset as “mpg”

Customizing Scatter Plots:

1. By changing the size of scatter plot points

Changing the size of scatter points

2. Setting the style and color of scatter points

2. LINE PLOTS-

Creating line plot with relplot() function of Seaborn library. Passing “kind” parameter equals to “line” will create line plot. Also, passing data , x and y as the input parameters.

Line plot

Visualizing standard deviation with line plot:

Passing “ci” parameter equals to “sd” gives the visualization of standard deviation in line plot.

Standard Deviation in line plot

Plotting subgroups in line plots:

Passing “ci” parameter equals to “None”

Setting the style and color of line plot:

Passing “style” parameter to change style and “hue” parameter to change the color.

Setting the markers in the line plot:

Changing the markers in the line plot by passing TRUE in the “markers” parameter.

setting markers in line plot

This brings us to the end of this article. I hope you have understood all the visualizations clearly. Make sure you practice as much as possible.

If you wish to check out more resources related to Data Science and Machine Learning you can refer to my Github account.

Do look out for other Jupyter notebooks in the series which will explain the various other aspects of Data Visualizations with Seaborn in Python.

You can also check my Data Science Portfolio on Github account.

Hope you like the post.

--

--

Ravjot Singh
The Startup

A Tech enthusiast || Dedicated and hardworking with a passion for Data Science || Codes in Python & R.