Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fill area under line plot in seaborn

I want to fill the area under a line plot so it looks as the picture below: it should look like it

instead of

enter image description here

built on the following .csv file:

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

what should I change in this code to generate the desired graph?

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()
like image 310
Степан Смирнов Avatar asked Aug 29 '18 19:08

Степан Смирнов


People also ask

How do I fill under a line in Matplotlib?

To fill the area under the curve, put x and y with ste="pre", using fill_between() method. Plot (x, y1) and (x, y2) lines using plot() method with drawstyle="steps" method. To display the figure, use show() method.

How do I fill a area in Matplotlib?

fill_between() is used to fill area between two horizontal curves. Two points (x, y1) and (x, y2) define the curves. this creates one or more polygons describing the filled areas.

How do I add transparency to seaborn plot?

To set a transparent background you could use the RGBA tuple (0,0,0,0) , where the last 0 represents an opacity of 0 .

How do I change my line style in seaborn?

Customize line style by passing a dict mapping to “dashes” “dashes” parameter is used along with “style” parameter. In a dictionary, you set a “category to style” mapping. The style will be in a tuple (as discussed in above section). Pass this dictionary mapping to “dashes” parameter.


1 Answers

plt.fill_between(df.Date.values, df.Data.values)
like image 152
VanTan Avatar answered Oct 01 '22 11:10

VanTan