Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

python - Second y-axis time series seaborn

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...