triple_quotes.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. """
  2. Created on Tue Apr 5 09:40:10 2016
  3. This code creates a line graph that compares the violent crime rates
  4. in Washington and Texas from 1960 to 2012, and also a map that shows
  5. the number of violent crimes per state in 2012.
  6. @author: Shane Aubain
  7. Ryan Buzzard
  8. Cassidy Deerin
  9. Tara King
  10. Valarie McLean
  11. Aaron Quartes III
  12. """
  13. """
  14. Line graph of Washington crime rates and Texas crime rates over time
  15. """
  16. import crime
  17. import matplotlib.pyplot as plt
  18. from matplotlib.legend_handler import HandlerLine2D
  19. allCrime = crime.get_all()
  20. texasCrime = allCrime["texas"]
  21. washCrime = allCrime["washington"]
  22. yearList = []
  23. texCrimeList = []
  24. washCrimeList = []
  25. for data in texasCrime["data"]:
  26. yearList.append(data["year"])
  27. texCrimeList.append(data["rates"]["violent"]["all"])
  28. for data in washCrime["data"]:
  29. washCrimeList.append(data["rates"]["violent"]["all"])
  30. line1, = plt.plot(yearList, texCrimeList, label="Texas crime")
  31. line2, = plt.plot(yearList, washCrimeList, label="Washington crime")
  32. plt.title("Texas and Washington crime rates over time")
  33. plt.xlabel("year")
  34. plt.ylabel("crime rate")
  35. plt.legend(handler_map={line1:HandlerLine2D(numpoints=4)}, loc=4)
  36. plt.show()
  37. """
  38. Number of violent crimes per state in 2012
  39. """
  40. import US_Map
  41. crimesPerState = [
  42. {'name': 'New Jersey', 'data': allCrime["new jersey"]["data"][52]["totals"]["violent"]["all"]},
  43. {'name': 'Rhode Island', 'data': allCrime["rhode island"]["data"][52]["totals"]["violent"]["all"]},
  44. {'name': 'Massachusetts', 'data': allCrime["massachusetts"]["data"][52]["totals"]["violent"]["all"]},
  45. {'name': 'Connecticut', 'data': allCrime["connecticut"]["data"][52]["totals"]["violent"]["all"]},
  46. {'name': 'Maryland', 'data': allCrime["maryland"]["data"][52]["totals"]["violent"]["all"]},
  47. {'name': 'New York', 'data': allCrime["new york"]["data"][47]["totals"]["violent"]["all"]},
  48. {'name': 'Delaware', 'data': allCrime["delaware"]["data"][52]["totals"]["violent"]["all"]},
  49. {'name': 'Florida', 'data': allCrime["florida"]["data"][52]["totals"]["violent"]["all"]},
  50. {'name': 'Ohio', 'data': allCrime["ohio"]["data"][52]["totals"]["violent"]["all"]},
  51. {'name': 'Pennsylvania', 'data': allCrime["pennsylvania"]["data"][52]["totals"]["violent"]["all"]},
  52. {'name': 'Illinois', 'data': allCrime["illinois"]["data"][52]["totals"]["violent"]["all"]},
  53. {'name': 'California', 'data': allCrime["california"]["data"][52]["totals"]["violent"]["all"]},
  54. {'name': 'Hawaii', 'data': allCrime["hawaii"]["data"][52]["totals"]["violent"]["all"]},
  55. {'name': 'Virginia', 'data': allCrime["virginia"]["data"][52]["totals"]["violent"]["all"]},
  56. {'name': 'Michigan', 'data': allCrime["michigan"]["data"][52]["totals"]["violent"]["all"]},
  57. {'name': 'Indiana', 'data': allCrime["indiana"]["data"][52]["totals"]["violent"]["all"]},
  58. {'name': 'North Carolina', 'data': allCrime["north carolina"]["data"][52]["totals"]["violent"]["all"]},
  59. {'name': 'Georgia', 'data': allCrime["georgia"]["data"][52]["totals"]["violent"]["all"]},
  60. {'name': 'Tennessee', 'data': allCrime["tennessee"]["data"][52]["totals"]["violent"]["all"]},
  61. {'name': 'New Hampshire', 'data': allCrime["new hampshire"]["data"][52]["totals"]["violent"]["all"]},
  62. {'name': 'South Carolina', 'data': allCrime["south carolina"]["data"][52]["totals"]["violent"]["all"]},
  63. {'name': 'Louisiana', 'data': allCrime["louisiana"]["data"][52]["totals"]["violent"]["all"]},
  64. {'name': 'Kentucky', 'data': allCrime["kentucky"]["data"][52]["totals"]["violent"]["all"]},
  65. {'name': 'Wisconsin', 'data': allCrime["wisconsin"]["data"][52]["totals"]["violent"]["all"]},
  66. {'name': 'Washington', 'data': allCrime["washington"]["data"][52]["totals"]["violent"]["all"]},
  67. {'name': 'Alabama', 'data': allCrime["alabama"]["data"][52]["totals"]["violent"]["all"]},
  68. {'name': 'Missouri', 'data': allCrime["missouri"]["data"][52]["totals"]["violent"]["all"]},
  69. {'name': 'Texas', 'data': allCrime["texas"]["data"][52]["totals"]["violent"]["all"]},
  70. {'name': 'West Virginia', 'data': allCrime["west virginia"]["data"][52]["totals"]["violent"]["all"]},
  71. {'name': 'Vermont', 'data': allCrime["vermont"]["data"][52]["totals"]["violent"]["all"]},
  72. {'name': 'Minnesota', 'data': allCrime["minnesota"]["data"][52]["totals"]["violent"]["all"]},
  73. {'name': 'Mississippi', 'data': allCrime["mississippi"]["data"][52]["totals"]["violent"]["all"]},
  74. {'name': 'Iowa', 'data': allCrime["iowa"]["data"][52]["totals"]["violent"]["all"]},
  75. {'name': 'Arkansas', 'data': allCrime["arkansas"]["data"][52]["totals"]["violent"]["all"]},
  76. {'name': 'Oklahoma', 'data': allCrime["oklahoma"]["data"][52]["totals"]["violent"]["all"]},
  77. {'name': 'Arizona', 'data': allCrime["arizona"]["data"][52]["totals"]["violent"]["all"]},
  78. {'name': 'Colorado', 'data': allCrime["colorado"]["data"][52]["totals"]["violent"]["all"]},
  79. {'name': 'Maine', 'data': allCrime["maine"]["data"][52]["totals"]["violent"]["all"]},
  80. {'name': 'Oregon', 'data': allCrime["oregon"]["data"][52]["totals"]["violent"]["all"]},
  81. {'name': 'Kansas', 'data': allCrime["kansas"]["data"][52]["totals"]["violent"]["all"]},
  82. {'name': 'Utah', 'data': allCrime["utah"]["data"][52]["totals"]["violent"]["all"]},
  83. {'name': 'Nebraska', 'data': allCrime["nebraska"]["data"][52]["totals"]["violent"]["all"]},
  84. {'name': 'Nevada', 'data': allCrime["nevada"]["data"][52]["totals"]["violent"]["all"]},
  85. {'name': 'Idaho', 'data': allCrime["idaho"]["data"][52]["totals"]["violent"]["all"]},
  86. {'name': 'New Mexico', 'data': allCrime["new mexico"]["data"][52]["totals"]["violent"]["all"]},
  87. {'name': 'South Dakota', 'data': allCrime["south dakota"]["data"][52]["totals"]["violent"]["all"]},
  88. {'name': 'North Dakota', 'data': allCrime["north dakota"]["data"][52]["totals"]["violent"]["all"]},
  89. {'name': 'Montana', 'data': allCrime["montana"]["data"][52]["totals"]["violent"]["all"]},
  90. {'name': 'Wyoming', 'data': allCrime["wyoming"]["data"][52]["totals"]["violent"]["all"]},
  91. {'name': 'Alaska', 'data': allCrime["alaska"]["data"][52]["totals"]["violent"]["all"]} ]
  92. US_Map.map_init()
  93. US_Map.color_US_map(crimesPerState)
  94. plt.title('Amount of Violent Crimes per State in 2012')
  95. plt.show()