Second y-axis time series seaborn

J. Doe picture J. Doe · Dec 1, 2017 · Viewed 41.2k times · Source

Using the data frame

df = pd.DataFrame({
    "date" : ["2018-01-01", "2018-01-02", "2018-01-03", "2018-01-04"],
    "column1" : [555,525,532,585],
    "column2" : [50,48,49,51]
})

one can plot with seaborn say column1 with sns.tsplot(data=df.column1, color="g").

How can we plot both time series with two y-axis in seaborn ?

Answer

Andrey Sobolev picture Andrey Sobolev · Dec 1, 2017

As seaborn is built on the top of matplotlib, you can use its power:

import matplotlib.pyplot as plt
sns.lineplot(data=df.column1, color="g")
ax2 = plt.twinx()
sns.lineplot(data=df.column2, color="b", ax=ax2)