In [10]:
import plotly.plotly as py
import plotly.graph_objs as go 
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
In [11]:
init_notebook_mode(connected=True) 
In [14]:
import pandas as pd
In [15]:
d = dict(type = 'choropleth',
            locations = ['AZ','CA','NY'],
            locationmode = 'USA-states',
            colorscale= 'Portland',
            text= ['text1','text2','text3'],
            z=[1.0,2.0,3.0],
            colorbar = {'title':'my titile'})
l = dict(geo = {'scope':'usa'})
In [16]:
choromap = go.Figure(data = [d],layout = l)
iplot(choromap)
In [5]:
df = pd.read_csv('2011_US_AGRI_Exports')
df.head()
Out[5]:
In [18]:
data = dict(type='choropleth',
            colorscale = 'YIOrRd',
            locations = df['code'],
            z = df['total exports'],
            locationmode = 'USA-states',
            text = df['text'],
            marker = dict(line = dict(color = 'rgb(255,255,255)',width = 2)),
            colorbar = {'title':"Millions USD"}
            ) 
In [22]:
layout = dict(title = '2011 US Agriculture Exports by State',
              geo = dict(scope='usa',
                         showlakes = True,
                         lakecolor = 'rgb(85,173,240)')
             )
In [23]:
choromap = go.Figure(data = [data],layout = layout)
In [24]:
iplot(choromap)
No comments:
Post a Comment