In [45]:
import plotly 
plotly.tools.set_config_file(world_readable=True,
                             sharing='public')

In [46]:
import plotly.plotly as py

In [47]:
from plotly.graph_objs import *

In [48]:
import pandas as pd

In [49]:
df = pd.read_csv('/Users/qiqi/DV590/Part2-Q3-data.csv')


/Users/qiqi/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.py:2717: DtypeWarning:

Columns (1,2) have mixed types. Specify dtype option on import or set low_memory=False.


In [50]:
df.head()


Out[50]:
z locations text Unnamed: 3 Unnamed: 4 Unnamed: 5 Unnamed: 6 Unnamed: 7 GDP Total Amount Awarded and Disbursed
0 156750.0 AL State: AL<br>Total Awarded Amount: 5743215<br>... NaN NaN NaN NaN NaN 156750.0 5743215.0
1 40063.0 AK State: AK<br>Total Awarded Amount: 16189749<br... NaN NaN NaN NaN NaN 40063.0 16189749.0
2 227358.0 AZ State: AZ<br>Total Awarded Amount: 19037687<br... NaN NaN NaN NaN NaN 227358.0 19037687.0
3 90319.0 AR State: AR<br>Total Awarded Amount: 1965330<br>... NaN NaN NaN NaN NaN 90319.0 1965330.0
4 1766693.0 CA State: CA<br>Total Awarded Amount: 74663752<br... NaN NaN NaN NaN NaN 1766693.0 74663752.0

In [97]:
scl = [[0.0, 'rgb(202,200,207)'],[0.2, 'rgb(178,178,195)'],[0.4, 'rgb(148,149,180)'],
            [0.6, 'rgb(118,114,160)'],[0.8, 'rgb(77,67,137)'],[1.0, 'rgb(44,9,103)']]

In [98]:
data = [ dict(
        type='choropleth',
        colorscale = scl,
        autocolorscale = False,
        locations = df['locations'],
        z = [156750,40063,227358,90319,1766693,220454,210170,53247,83586,700267,388342,58573,47176,586442,245197,123353,104884,143875,199683,46277,263809,345059,395166,243933,81678,224091,30637,73455,118785,57282,443148,74403,1023433,357168,24622,467392,125243,147535,506505,45663,143585,31380,227505,990054,94475,23539,359273,296403,53453,226325,27454], 
        locationmode = 'USA-states',
       text = ["State: AL<br>Total Awarded Amount: 5743215<br>GDP(million):   156750",
"State: AK<br>Total Awarded Amount: 16189749<br>GDP(million): 40063",
"State: AZ<br>Total Awarded Amount: 19037687<br>GDP(million): 227358",
"State: AR<br>Total Awarded Amount: 1965330<br>GDP(million): 90319",
"State: CA<br>Total Awarded Amount: 74663752<br>GDP(million): 1766693",
"State: CO<br>Total Awarded Amount: 22235728<br>GDP(million): 220454",
"State: CT<br>Total Awarded Amount: 16501999<br>GDP(million): 210170",
"State: DE<br>Total Awarded Amount: 3857523<br>GDP(million): 53247",
"State: DC<br>Total Awarded Amount: 25424106<br>GDP(million): 83586",
"State: FL<br>Total Awarded Amount: 26600593<br>GDP(million): 700267",
"State: GA<br>Total Awarded Amount: 11216327<br>GDP(million): 388342",
"State: HI<br>Total Awarded Amount: 14427899<br>GDP(million): 58573",
"State: ID<br>Total Awarded Amount: 1961349<br>GDP(million): 47176",
"State: IL<br>Total Awarded Amount: 68112505<br>GDP(million): 586442",
"State: IN<br>Total Awarded Amount: 16377153<br>GDP(million): 245197",
"State: IA<br>Total Awarded Amount: 8493716<br>GDP(million): 123353",
"State: KS<br>Total Awarded Amount: 5764416<br>GDP(million): 104884",
"State: KY<br>Total Awarded Amount: 8022942<br>GDP(million): 143875",
"State: LA<br>Total Awarded Amount: 7978539<br>GDP(million): 199683",
"State: ME<br>Total Awarded Amount: 11177079<br>GDP(million): 46277",
"State: MD<br>Total Awarded Amount: 21671260<br>GDP(million): 263809",
"State: MA<br>Total Awarded Amount: 45976945<br>GDP(million): 345059",
"State: MI<br>Total Awarded Amount: 28799226<br>GDP(million): 395166",
"State: MN<br>Total Awarded Amount: 15325162<br>GDP(million): 243933",
"State: MS<br>Total Awarded Amount: 2787779<br>GDP(million): 81678",
"State: MO<br>Total Awarded Amount: 14911587<br>GDP(million): 224091",
"State: MT<br>Total Awarded Amount: 10424194<br>GDP(million): 30637",
"State: NE<br>Total Awarded Amount: 6600356<br>GDP(million): 73455",
"State: NV<br>Total Awarded Amount: 3677624<br>GDP(million): 118785",
"State: NH<br>Total Awarded Amount: 4797223<br>GDP(million): 57282",
"State: NJ<br>Total Awarded Amount: 11475362<br>GDP(million): 443148",
"State: NM<br>Total Awarded Amount: 10640574<br>GDP(million): 74403",
"State: NY<br>Total Awarded Amount: 105860170<br>GDP(million): 1023433",
"State: NC<br>Total Awarded Amount: 29992038<br>GDP(million): 357168",
"State: ND<br>Total Awarded Amount: 3071608<br>GDP(million): 24622",
"State: OH<br>Total Awarded Amount: 22015009<br>GDP(million): 467392",
"State: OK<br>Total Awarded Amount: 12405823<br>GDP(million): 125243",
"State: OR<br>Total Awarded Amount: 9556529<br>GDP(million): 147535",
"State: PA<br>Total Awarded Amount: 59575053<br>GDP(million): 506505",
"State: RI<br>Total Awarded Amount: 4751919<br>GDP(million): 45663",
"State: SC<br>Total Awarded Amount: 9063478<br>GDP(million): 143585",
"State: SD<br>Total Awarded Amount: 3596551<br>GDP(million): 31380",
"State: TN<br>Total Awarded Amount: 18083590<br>GDP(million): 227505",
"State: TX<br>Total Awarded Amount: 48252344<br>GDP(million): 990054",
"State: UT<br>Total Awarded Amount: 6884351<br>GDP(million): 94475",
"State: VT<br>Total Awarded Amount: 6381133<br>GDP(million): 23539",
"State: VA<br>Total Awarded Amount: 18068081<br>GDP(million): 359273",
"State: WA<br>Total Awarded Amount: 23476750<br>GDP(million): 296403",
"State: WV<br>Total Awarded Amount: 927680<br>GDP(million): 53453",
"State: WI<br>Total Awarded Amount: 17075827<br>GDP(million): 226325",
"State: WY<br>Total Awarded Amount: 2210361<br>GDP(million): 27454"],
        marker = dict(
            line = dict (
                color = 'rgb(255,255,255)',
                width = 2
            ) ),
        colorbar = dict(
            title = "GDP(million)")
        ) ]

In [99]:
#layout = dict(
        #title = '2005 US GDP Distribution<br>(Compared with total awarded amount)',
        #geo = dict(
            #scope='',
            #projection=dict( type='albers usa' ),
            #showlakes = True,
            #lakecolor = 'rgb(255, 255, 255)'),
             #)

layout = dict(
    title = '2005 US GDP Distribution<br>(Compared with total awarded amount)',
    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
        )
    )
)

In [100]:
fig = dict( data=data, layout=layout )

In [102]:
py.iplot(fig)


Out[102]:

In [ ]: