首页 > 解决方案 > Plotly express 或 Go - 地图县内的标签

问题描述

我正在尝试根据“更改”或“县”项目在瓷砖上贴标签,如下所示。我无法实现它。下面是我的示例代码。

fig = px.choropleth(stat_data, geojson=geo_json_data, color="CHANGE",
                    locations="COUNTY", featureidkey="properties.COUNTY",
                    projection="mercator",
                    color_continuous_scale=px.colors.diverging.RdYlGn, color_continuous_midpoint=2
                          )

fig.update_geos(fitbounds="locations", visible=False)
fig.show()

我尝试使用 plotlyexpress 或 go 方法以及其他论坛上答案中显示的建议,看起来它仅适用于图形工厂,因为 scatter 方法仅适用于那个。

任何帮助将不胜感激。

在此处输入图像描述

标签: dictionarylabelplotly

解决方案


我在这里找到了答案:https ://community.plotly.com/t/annotations-on-plotly-choropleth/36219

fig.add_scattergeo(
  geojson=counties,
  locations = df['names'],
  text = df['values'],
  featureidkey="properties.NAME_3",
  mode = 'text') 

推荐阅读