如何在go.Scattergeo中根据数值列表设置标记大小与颜色?
基于counts列表调整Scattergeo标记的大小/颜色
你可以通过在go.Scattergeo的marker参数中绑定counts列表,实现标记大小或颜色的动态调整,具体方案如下:
1. 调整标记大小
通过marker.size绑定counts,还可通过缩放系数或sizemode优化显示效果:
fig = go.Figure(data=go.Scattergeo( mode = 'markers', lon = long, lat = lat, marker=dict( size=[c * 2 for c in counts], # 用缩放系数调整标记尺寸,可按需修改 sizemode='area' # 可选,让大小基于面积变化,视觉上更直观 ) )) fig.update_layout(geo_scope='europe', width=1200, height=800) fig.update_geos(showsubunits=True) fig.show()
2. 调整标记颜色
通过marker.color绑定counts,搭配颜色刻度条展示数值对应关系:
fig = go.Figure(data=go.Scattergeo( mode = 'markers', lon = long, lat = lat, marker=dict( color=counts, # 直接关联counts数值 colorscale='Viridis', # 可选颜色方案,比如'RdYlBu'、'Plasma' colorbar=dict(title='Counts') # 添加颜色刻度条,标注数值含义 ) )) fig.update_layout(geo_scope='europe', width=1200, height=800) fig.update_geos(showsubunits=True) fig.show()
3. 同时调整大小和颜色
将上述两种配置结合,实现双重维度的视觉区分:
fig = go.Figure(data=go.Scattergeo( mode = 'markers', lon = long, lat = lat, marker=dict( size=[c * 2 for c in counts], sizemode='area', color=counts, colorscale='Viridis', colorbar=dict(title='Counts') ) )) fig.update_layout(geo_scope='europe', width=1200, height=800) fig.update_geos(showsubunits=True) fig.show()
内容的提问来源于stack exchange,提问作者Christian01
相关产品推荐
相关产品推荐

