I want to fill the area under a line plot so it looks as the picture below:
instead of
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()
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.
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.
To set a transparent background you could use the RGBA tuple (0,0,0,0) , where the last 0 represents an opacity of 0 .
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.
plt.fill_between(df.Date.values, df.Data.values)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With