Skip to content

Instantly share code, notes, and snippets.

@southpolemonkey
Created December 4, 2019 04:01
Show Gist options
  • Save southpolemonkey/2edfb7d0ec24d257cdb37bb82701adf3 to your computer and use it in GitHub Desktop.
Save southpolemonkey/2edfb7d0ec24d257cdb37bb82701adf3 to your computer and use it in GitHub Desktop.
matplotlib - two bar charts
import numpy as np
import matplotlib.pyplot as plt
# data to plot
n_groups = 4
means_frank = (90, 55, 40, 65)
means_guido = (85, 62, 54, 20)
# create plot
fig, ax = plt.subplots()
index = np.arange(n_groups)
bar_width = 0.35
opacity = 0.8
rects1 = plt.bar(index, means_frank, bar_width,
alpha=opacity,
color='b',
label='Frank')
rects2 = plt.bar(index + bar_width, means_guido, bar_width,
alpha=opacity,
color='g',
label='Guido')
plt.xlabel('Person')
plt.ylabel('Scores')
plt.title('Scores by person')
plt.xticks(index + bar_width, ('A', 'B', 'C', 'D'))
plt.legend()
plt.tight_layout()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment