Issue
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.
fig, ax = plt.subplots()
joinedDF.plot(x='date', y='count', figsize = (15, 8), ax = ax)
ax.set_xlabel("Date")
ax.set_ylabel("Count")
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);
Answered By - Peter Leimbigler
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.