Fill in between two lines with csv data

36 Views Asked by At

I am trying to create a background for a plot to show a filled area representing mean values of several lines by creating a fill in between two lines (max and min values as shown by the grey area in the image) in my csv data. I'd like to add my own data on top (as simple lines) but for now I just cannot understand why the fill in between two lines doesn't work.

I am trying to obtain this kind of plot at the end

I tried different things but I am quite new at coding and I don't really know what could be the problem. The closest I have been to the final plot I was expecting was with this code :

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

path_csv = "test_csv_area.csv"

df = pd.read_csv(path_csv, sep=';')

figure1 = fig, ax = plt.subplots()

x = df.index = ('La', 'Ce', 'Pr', 'Nd', 'Sm', 'Eu', 'Gd', 'Tb', 'Dy', 'Y', 'Ho', 'Er', 'Tm', 'Yb', 'Lu')
y1 = df.data2 = ['data_2']

y2 = df.data3 = ['data_3']

#the data is from my csv file with my columns called 'data_2' and 'data_3'

df[['data_3', 'data_2']].plot(logy=True)

plt.fill_between(x, y1, y2,
color=(0.8, 0.9, 0.5));

plt.xticks(np.arange(15), df.index)

plt.show()

--> I have one column with my index values but I couldn't have them on the x axis by citing the column so I have written down the indexes. My Y axis doesn't show the log scale and the biggest problem is obviously that the filling is not between the two lines but in background. I wanted something like that : image found on a forum and obtained something like that for now : image obtained with my data.

Does anyone have an idea of what could be changed in my code to succeed to this ? Thank you very much !

0

There are 0 best solutions below