I have a pandas dataframe like so:
Date Allotment NDII_Mean NDVI_Mean RGR_Mean SATVI_Mean
1984137 Arnston -0.053650 0.414868 0.938309 0.332712
1984185 Arnston 0.074928 0.558329 0.867951 0.334555
1984249 Arnston -0.124691 0.352225 1.041513 0.331821
1985139 Arnston -0.075537 0.468092 0.929414 0.383750
1985171 Arnston 0.017400 0.493443 0.889835 0.314717
1986206 Annex 0.151539 0.626690 0.775202 0.332507
1986238 Annex 0.142235 0.604764 0.823083 0.303600
1987241 Annex -0.005423 0.506760 0.911124 0.338675
1987257 Annex -0.058166 0.449052 0.961348 0.336879
I want to plot based on allotment, so I will need to use groupby. So for each Allotment I want the Date on the X-Axis, and all four of the columns with mean in the name shown as lines on the graph and their values on the Y-Axis. I will then save them as pdf's, although it is not necessary that I do if someone knows another way. I can plot ONE value using this code (I'll lot NDII_Mean in this example) but I want to plot all four of the columns not just one. The code I am using is:
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
df=pd.read_csv('C:/Users/Stefano/Documents/Hurst_plots.csv')
with PdfPages('C:/Users/Stefano/Documents/Hurst_plots.pdf') as pdf:
for i, group in df.groupby('Allotment'):
plt.ylabel('Values')
plt.figure()
Hurst_plots=group.plot(x='Date', y='NDII_Mean',title=str(i)).get_figure()
pdf.savefig(Hurst_plots)
This is what one of the plots looks like (different than data shown because I shortened my example table):
edit:
This works by adding editing this line
Hurst_plots=group.plot(x='Date', y=['NDII_Mean', 'RGR_Mean', 'SATVI_Mean', 'SWIR32_Mean'],title=str(i)).get_figure()
but does anyone know how to take the legend outside of the graph completely?