Seaborn tsplot() in Python

Manav Narula May 07, 2021
Seaborn tsplot() in Python

In this tutorial, we will learn how to use the seaborn.tsplot() function in Seaborn.

The seaborn.tsplot() is a very robust and useful function. It is used when we have the timestamp for the data available. It is used to plot one or more time-series data. The data can be either in the form of a long DataFrame or an N-Dimensional array with dimensions in units and time.

This function can also plot multiple time-series data easily and efficiently. We can customize the final plot using a variety of parameters lie unit, condition, and more. The unit parameter can be a series or DataFrame column used to identify the sampling unit, and the condition parameter can identify the condition of the data or its categories.

We can alter the final line using the color, linewidth parameters to make the plot visually more appealing.

In the following code, we will plot a graph using this function.

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

df = pd.DataFrame(
        "Date": [
        "Price 1": [77, 76, 68, 70, 78, 79, 74, 75],
df["Date"] = pd.to_datetime(df["Date"], format="%d%m%Y")

sns.tsplot(data=df["Price 1"], time=df["Date"], color="blue", linewidth=5)

seaborn tsplot function

It should be worth knowing that although this function is very powerful for plotting time-series data, it was deprecated in the January 2020 version of the seaborn module. It is advised to use the seaborn.lineplot() function as its alternative.

Author: Manav Narula
Manav Narula avatar Manav Narula avatar

Manav is a IT Professional who has a lot of experience as a core developer in many live projects. He is an avid learner who enjoys learning new things and sharing his findings whenever possible.