【问题标题】:plotly scattermapbox - issue with markers/plotting coordinatesplotly scattermapbox - 标记/绘图坐标问题
【发布时间】:2018-10-12 21:48:51
【问题描述】:

我有一些代码可以创建一个字典列表,其中包含要在地图和布局对象上绘制的坐标。地图渲染得很好,但是没有任何标记或坐标。数据对象包含一个坐标列表,所以我怀疑 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}},
 .
 .
 .

【问题讨论】:

    标签: python pandas plotly plotly-dash


    【解决方案1】:

    这里是修复:

    "lat": [lat],
    
    "lon": [long]
    

    需要是listnumpy arraytuple

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多