Guest User

Untitled

a guest
Oct 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. In the previous exercise, you didn't specify the number of bins. By default, Python sets the number of bins to 10 in that case. The number of bins is pretty important. Too little bins oversimplifies reality, which doesn't show you the details. Too much bins overcomplicates reality and doesn't give the bigger picture.
  2.  
  3. To control the number of bins to divide your data in, you can set the bins argument.
  4.  
  5. That's exactly what you'll do in this exercise. You'll be making two plots here. The code in the script already includes plt.show() and plt.clf() calls; plt.show() displays a plot; plt.clf() cleans it up again so you can start afresh.
  6.  
  7. As before, life_exp is available and matploblib.pyplot is imported as plt.
  8.  
  9. Build a histogram of life_exp, with 5 bins. Can you tell which bin contains the most observations?
  10. Build another histogram of life_exp, this time with 20 bins. Is this better?
  11.  
  12. # Build histogram with 5 bins
  13. import matplotlib.pyplot as plt
  14. plt.hist(life_exp, bins=5)
  15. # Show and clean up plot
  16. plt.show()
  17. plt.clf()
  18.  
  19. # Build histogram with 20 bins
  20. plt.hist(life_exp, bins=20)
  21.  
  22. # Show and clean up again
  23. plt.show()
  24. plt.clf()
Add Comment
Please, Sign In to add comment