I am trying to make a bar plot with two values for two classes A and B using matplotlib.
My values are a = 43 and b = 21.
I need the plot to look like this:

I have been trying to do it almost an hour using matplotlib examples but eventually gave up. Maybe somebody can help me out?
As of mpl 1.5 you can simply do:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.bar([1, 2], [43, 21], width=1,
tick_label=['A', 'B'], align='center')

Use bar():
import matplotlib.pyplot as plt
fig = plt.figure()
s = fig.add_subplot(111)
s.bar([1, 2], [43, 21], width=1)
s.set_xlim(0.5, 3.5)
fig.savefig('t.png')

Edit: following the specs more accurately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With