Hello I recently downloaded and installed plotly in order to create a Choropleth U.S. map of Zika cases in the iPython notebook. Here is my code for the Choropleth map:
scl = [[0.0, ‘rgb(242,240,247)’],[0.2, ‘rgb(218,218,235)’],[0.4, ‘rgb(188,189,220)’],
[0.6, ‘rgb(158,154,200)’],[0.8, ‘rgb(117,107,177)’],[1.0, ‘rgb(84,39,143)’]]
df[‘text’] = df[‘state’]
data = [dict(
type=‘choropleth’,
colorscale = scl,
autocolorscale = False,
locations = df[‘state’],
z = df[‘total’].astype(float),
locationmode = ‘USA-states’,
text = df[‘text’],
hoverinfo = ‘location+z’,
marker = dict(
line = dict (
color = ‘rgb(255,255,255)’,
width = 2
)
),
colorbar = dict(
title = “Zika Virus Cases”
)
)]
layout = dict(
title = ‘Zika Virus Cases in the U.S. from 2015-2016
(Hover for breakdown)’,
geo = dict(
scope=‘usa’,
projection=dict( type=‘albers usa’ ),
showlakes = True,
lakecolor = ‘rgb(255, 255, 255)’
)
)
fig = dict(data=data, layout=layout)
py.iplot(fig, validate=True, filename=‘zika_map’)
Now, df is a Panda data frame object which holds the zika data for each U.S. state and is represented as the following:
df.columns = [“state”, “travel”, “local”, “total”, “percent”]
df.tail()
STATE_TERRITORY TRAVEL_CASE LOCAL_CASE TOTAL_CASES PERCENTAGE
46 Virginia 15 0 15 1.087000
47 Washington 2 0 2 0.145000
48 West Virginia 6 0 6 0.435000
49 Wisconsin 0 0 0 0.000000
50 Wyoming 0 0 0 0.000000
While the above code prints a map with the correct color bar, colors do not display accordingly on the map nor does the text marker work for any of the states.
Please help me display the colors correctly on the U.S. map along with the text markers.
Thanks!