我有一些代码可以创建字典列表,并带有要在地图和布局对象上绘制的坐标。该地图可以很好地渲染,但是没有任何标记或坐标。数据对象包含一个坐标列表,所以我怀疑是plotly / scattermapbox有问题。
这是我的代码:
def update_graph(selected_value):
# Filter the dataframe with selected value
Comp_data = EmpComm1[EmpComm1['Company'] == selected_value]
data = []
# Plot home location and map commute to work.
# Create a data dictionary of lat and lon to plot
for i, row in Comp_data.iterrows():
lat, long = row['HomeLocation']
data.append({
"type": "scattermapbox",
"lat": lat,
"lon": long,
"mode": "markers",
"marker": {
"symbol": "circle-dot",
"color": "grey",
"size": 10,
"opacity": 0.7
}
})
layout = {
"autosize": True,
"hovermode": "closest",
"mapbox": {
"accesstoken": MAPBOX_KEY,
"bearing": 0,
"center": {
"lat": 37.77,
"lon": -122.43
},
"pitch": 0,
"zoom": 10,
"style": "outdoors"
}
}
return {"data": data, "layout": layout}
数据对象:
[{'type': 'scattermapbox',
'lat': 37.70542367598618,
'lon': -121.83596766086245,
'mode': 'markers',
'marker': {'size': 3, 'opacity': 1.0}},
{'type': 'scattermapbox',
'lat': 37.5646475449362,
'lon': -121.78437649150582,
'mode': 'markers',
'marker': {'size': 3, 'opacity': 1.0}},
.
.
.
答案 0 :(得分:0)
解决方法:
"lat": [lat],
"lon": [long]
需要为list
,numpy array
或tuple
。