Reputation: 10784
I'm looking for an option to create a bar diagram that combines 1 bar (per index) and 2 bars.
something like this:
I could fake it making a 2 bar diagram, putting 0 to the first group of bars and then drawing a bar manually... but is there a more elegant way to do it?
Thanks
Upvotes: 2
Views: 275
Reputation: 88148
You can adapt as needed, but the key here is that plt.bar
takes in a third parameter of the bar width. We can use that and scale the x-coordinate to create the effect you are looking for.
import numpy as np
import pylab as plt
bar_width = 0.3
plt.bar([0,],[3,],2*bar_width,color='k',alpha=.7)
X = np.array([1,2,3])
Y0 = [2,5,7]
Y1 = [5,3,1]
plt.bar(X,Y0,bar_width,color='b',alpha=.7)
plt.bar(X+bar_width,Y1,bar_width,color='r',alpha=.7)
plt.show()
Upvotes: 2