Reputation: 349
I need to put both a boxplot and a bar plot in the same graph. I have a dataframe like this:
Suppose I recebe the data like this:
df = pd.DataFrame([np.random.normal(0,1,10), \
np.random.normal(0,1,10)],
index=["A", "B"])
In order to have the index as columns I transpose the df
df = df.transpose()
Now I want to overlap a box plot with for columns A and B and a Bar Plot with the mean of each column.
How I can overlap them using matplotlib once they are different types?
thanks,
Upvotes: 4
Views: 3386
Reputation: 153460
Get the handle for the axes, the plot the second on that axes using ax=ax
.
ax = df.plot.box()
_ = df.T.plot.bar(ax=ax)
plt.show()
Upvotes: 6