使用数据框
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
绘图,用column1
说sns.tsplot(data=df.column1, color="g")
。我们如何在seaborn中绘制两个带有两个y轴的时间序列?
最佳答案
我建议使用法线图。您可以通过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()
关于python - 第二y轴时间序列seaborn,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47591650/