I have a pandas dataframe that I'm trying to plot as a line graph. I have a column that indicates true or false based on the time period, and all I'm looking to do is to have my line graph shaded by different colors based on that value.
This is what my dataframe looks like:
date value1 value2 value3 yesno
1/1/2017 4.092913986 0.983422333 4.702443788 1
1/2/2017 1.297297396 0.944562353 93.28873738 1
1/3/2017 9.340254094 0.29748964 63.0201697 0
1/4/2017 1.785673265 0.266832844 15.82940576 0
1/5/2017 1.795707079 0.059327578 76.17126027 0
1/6/2017 6.973433264 0.606546753 92.23754049 0
1/7/2017 4.720144158 0.007475406 90.90629644 0
1/8/2017 6.654395447 0.345946112 55.06564897 1
1/9/2017 5.066128977 0.636196266 79.01661793 1
1/10/2017 5.036420596 0.71724815 99.56291692 0
1/11/2017 9.056591185 0.413846139 62.96214739 1
1/12/2017 2.351980932 0.021501056 53.48078161 0
1/13/2017 4.010542244 0.381479612 78.55923149 0
1/14/2017 0.175470941 0.152152033 35.02354055 0
1/15/2017 5.702023064 0.717303458 85.70226712 1
1/16/2017 2.970976482 0.816395807 37.39305001 1
1/17/2017 0.186432777 0.218164339 44.57253955 0
I know there's the axvspan function, but how do I apply it to this? thanks for your help!
x= useperftable['date']
y= useperftable[['value1','value2','value3']]
bo = useperftable['yesno']
fig, ax = plt.subplots()
ax.fill_between(x, 0, 1, where=bo, alpha=0.4, transform=ax.get_xaxis_transform())
plt.plot(x,y)
plt.show()