In [20]:
#Contribute to Yuxiang Ling#
import plotly
plotly.tools.set_credentials_file(username='huilyu2', api_key='LYEkqxDQFmZzZIBXn9rn')
import plotly.plotly as py
In [21]:
import pandas as pd
In [22]:
df = pd.read_csv('/Users/yiling10/Downloads/Administrative_Discretionary_Grants_Dataset.csv')
In [23]:
df.head()
Out[23]:
In [24]:
df['text'] = df['Program'] +'<br>'+ 'Total Amount Awarded and Disbursed: ' + (df['Total Amount Awarded and Disbursed']/1e3).astype(str)+'thousand'+'<br>'+ 'State: '+ df['State']
limits = [(0,10),(10,100),(100,200),(200,500),(500,1000),(1000,3000)]
colors = ["rgb(92,167,186)","rgb(131,175,155)","rgb(200,200,169)","rgb(249,205,173)","rgb(252,157,154)","rgb(254,67,101)"]
Programs = []
scale = 6000
In [25]:
for i in range(len(limits)):
lim = limits[i]
df_sub = df[((df['Total Amount Awarded and Disbursed']/1e3)<limits[i][1])&((df['Total Amount Awarded and Disbursed']/1e3)>limits[i][0])]
program = dict(
type = 'scattergeo',
locationmode = 'USA-states',
lon = df_sub['LNG'],
lat = df_sub['LAT'],
text = df_sub['text'],
marker = dict(
size = df_sub['Total Amount Awarded and Disbursed']/scale,
color = colors[i],
line = dict(width=0.5, color='rgb(255,255,255)'),
opacity = 0.7,
sizemode = 'area'
),
name = '{0} - {1}'.format(limits[i][0],limits[i][1]) )
Programs.append(program)
layout = dict(
geo = dict(
scope = 'north america',
showland = True,
landcolor = "rgb(212, 212, 212)",
subunitcolor = "rgb(255, 255, 255)",
countrycolor = "rgb(255, 255, 255)",
showlakes = True,
lakecolor = "rgb(255, 255, 255)",
showsubunits = True,
showcountries = True,
resolution = 50,
projection = dict(
type = 'conic conformal',
rotation = dict(
lon = -100
)
),
lonaxis = dict(
showgrid = True,
gridwidth = 0.5,
range= [ -140.0, -55.0 ],
dtick = 5
),
lataxis = dict (
showgrid = True,
gridwidth = 0.5,
range= [ 20.0, 60.0 ],
dtick = 5
)
),
title = 'Total Amount Awarded and Disbursed<br>(Click legend to toggle traces)')
fig = dict( data=Programs, layout=layout )
py.iplot( fig, validate=False, filename='Total_Amount_Awarded_and_Disbursed' )
Out[25]:
In [ ]:
In [4]:
In [5]:
In [6]:
In [7]:
In [8]:
In [ ]: