如何在seaborn中填充线图下的区域

时间:2018-08-29 19:00:29

标签: python visualization seaborn line-plot

我想填充线图下的区域,因此它如下图所示: it should look like it

代替

enter image description here

基于以下.csv文件构建:

01-01-97    1
01-02-97    2
01-03-97    3
     ...
01-11-17    251
01-12-17    252
01-01-18    253

我应该在此代码中进行哪些更改以生成所需的图形?

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

# load csv
df=pd.read_csv("test.csv")
# generate graph
g = sns.lineplot(x="Date", y="Data", data=df)

plt.show()

2 个答案:

答案 0 :(得分:2)

这里是一种替代方法,使用堆积折线图:

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

# load csv
df = pd.read_csv("test.csv")

# generate graph
plt.stackplot(df["Date"], df["Data"], alpha=0.5) 

plt.show()

答案 1 :(得分:1)

plt.fill_between(df.Date.values, df.Data.values)