I am trying to show a scatter plot on a plotly world map. The code runs in a jupyter notebook.
Here is the code
mpis = []
colors = ["rgb(0,116,217)","rgb(255,65,54)","rgb(133,20,75)","rgb(255,133,27)","lightgrey"]
for i in range(len(mpi)):
mpis.append(
dict(
type = 'scattergeo',
#locationmode = 'world',
lon = mpi['lon'][i],
lat = mpi['lat'][i],
text = str(mpi['MPI'][i]),
marker = dict(
size = 10,# mpi['MPI'][i]*100,
color = colors[i%len(colors)],
line = dict(width=0.5, color='rgb(40,40,40)'),
sizemode = 'area'
),)
)
layout = go.Layout(
title = 'MPI',
geo = dict(
scope='world',
#projection=dict( type = 'Mercator'),
showland = True,
landcolor = 'rgb(217, 217, 217)',
subunitwidth=1,
countrywidth=1,
subunitcolor="rgb(255, 255, 255)",
countrycolor="rgb(255, 255, 255)"
),)
fig = dict( data=mpis, layout=layout ) #fig = go.Figure(layout=layout, data=mpis)
iplot( fig, validate=False)
This is an example of object in the data
{'lat': 36.734772499999998,
'lon': 70.811995299999978,
'marker': {'color': 'rgb(0,116,217)',
'line': {'color': 'rgb(40,40,40)', 'width': 0.5},
'size': 10,
'sizemode': 'area'},
'text': '',
'type': 'scattergeo'},
but the result is the map is shown without any shape drawn.
mpi; however, in your code you havempi['lon'][i]and'lon'in your object is a number, thus cannot be indexed.