第二个 y 轴时间序列 seaborn [英] Second y-axis time series seaborn

查看:47
本文介绍了第二个 y 轴时间序列 seaborn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用数据框

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]
})

可以用 seaborn 绘图,比如 column1sns.tsplot(data=df.column1, color="g").

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

我们如何在 seaborn 中用两个 y 轴绘制两个时间序列?

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

推荐答案

我建议使用法线图.您可以通过 ax.twinx() 获得双轴.

I would recommend using a normal line plot. You can get a twin axes via ax.twinx().

import pandas as pd
import matplotlib.pyplot as plt

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]})

ax = df.plot(x="date", y="column1", legend=False)
ax2 = ax.twinx()
df.plot(x="date", y="column2", ax=ax2, legend=False, color="r")
ax.figure.legend()
plt.show()

这篇关于第二个 y 轴时间序列 seaborn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆