Reputation: 111
I have a bar plot that I want to plot a line over that connects the top of the bars to see a general trend. My code currently looks like this (note - ratio is a pandas dataframe with column data_points):
ratio['data_points'].plot(kind='bar')
ratio['data_points'].plot()
plt.title('')
plt.show()
And I get back a plot that looks like this:
I'm not sure how to alter this so that the bar plot shows properly (ie, the full bar for Week 1 and Week 4 are actually on the plot) and how to make it so that the line plot just connects the tops of the bars (the fall to 0 on week 3 is fine still - I don't need week 2 to connect to week 4 unless that's the only way to do this)
Upvotes: 2
Views: 1674
Reputation: 150735
You can do:
zorder
than bar
Like this:
ratio.data_points.plot(zorder=5)
ratio['data_points'].plot(kind='bar', color='C2', zorder=1)
plt.title('')
plt.show()
Output:
Upvotes: 2