Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Added shared error around Pandas line plot

I have a nice looking line plot, but I want to add shaded areas designating the margin of error above and below my existing line. I have a column with the error already calculated in my pandas data frame, but I am unsure how to add it to my plot.

enter image description here

fig, ax = plt.subplots()
joinedDF.plot(x='date', y='count', figsize = (15, 8), ax = ax)
ax.set_xlabel("Date")
ax.set_ylabel("Count")

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Based on the pandas plotting documentation, and assuming your DataFrame joinedDF has the error in a column named err, run this after your current code:

plt.fill_between(joinedDF['date'], 
                 joinedDF['count'] - joinedDF['err'], 
                 joinedDF['count'] + joinedDF['err'], 
                 color='b', 
                 alpha=0.2);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading