@Annvil/

PythonDataVisualizer

Python

No description

fork
loading
Files
  • main.py
  • budgets.png
  • GDP.csv
  • gdp.png
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import matplotlib as mpl
import matplotlib.pyplot as plt
import csv
import requests

def plot_gdp():
  plt.clf()
  with open('GDP.csv', 'r') as csvfile:
      gdp_reader = csv.reader(csvfile, delimiter=',')

      first_row = True
      for row in gdp_reader:
        if first_row:
          first_row = False
          continue

        gdp_values = [float(cell) for cell in row[2:59]]
        plt.plot(range(1960,2017), gdp_values, label=row[1])

  plt.title("GDP History per Capita")
  plt.legend(shadow=True, loc="upper left")
  plt.show()
  plt.savefig('gdp.png')

def plot_agency():
  plt.clf()
  j_resp = requests.get("https://api.usaspending.gov/api/v2/references/toptier_agencies/").json()
  
  resp = j_resp["results"]
  agencies = []
  budgets = []
  small_agencies = float(0)

  for agency in resp:
    budget_amt = float(agency["budget_authority_amount"])
    if(budget_amt > 100000000000):
      agencies.append(agency["agency_name"])
      budgets.append(budget_amt)
    else:
      small_agencies+=budget_amt
  
  if(small_agencies > 0):
    agencies.append("Other")
    budgets.append(small_agencies)

  plt.title("Agency Budgets")
  plt.pie(budgets, labels=agencies, autopct='%.1f%%')
  plt.show()
  plt.savefig('budgets.png')

plot_gdp()
plot_agency()