Advertisement
lalkaed

BarChart

Sep 7th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. import codecademylib
  2. from matplotlib import pyplot as plt
  3.  
  4. unit_topics = ['Limits', 'Derivatives', 'Integrals', 'Diff Eq', 'Applications']
  5. middle_school_a = [80, 85, 84, 83, 86]
  6. middle_school_b = [73, 78, 77, 82, 86]
  7.  
  8. def create_x(t, w, n, d):
  9.     return [t*x + w*n for x in range(d)]
  10. school_a_x = create_x(2, 0.8, 1, 5)
  11. school_b_x = create_x(2, 0.8, 2, 5)
  12. # Make your chart here
  13. plt.figure(figsize=(10,8))
  14. ax = plt.subplot()  
  15. plt.bar(school_a_x, middle_school_a)
  16. plt.bar(school_b_x,middle_school_b)
  17. middle_x = [ (a + b) / 2.0 for a, b in zip(school_a_x, school_b_x)]
  18.  
  19. ax.set_xticks(middle_x)
  20. ax.set_xticklabels(unit_topics)
  21.  
  22. plt.legend(["Middle School A", "Middle School B"])
  23. plt.title('Test Averages on Different Units')
  24. plt.ylabel('test average')
  25. plt.xlabel('unit')
  26. plt.show()
  27. plt.savefig('my_side_by_side.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement