Plotly ScatterGeo 文本颜色

问题描述 投票:0回答:1

我正在使用plotly 制作分区统计图。

我想使用Fig.add_scattergeo向地图添加文本标签,但它借用了绘图中的颜色映射,而且看起来不太好。文字与背景颜色没有对比,难以阅读。

我想知道是否以及如何修改Fig.add_scattergeo生成的文本轨迹以获得更好的对比度。

enter image description here

代码:

# Create a choropleth map with state names
fig = px.choropleth(
    top_sectors_empl,
    locations="st",  # Column with state names
    locationmode="USA-states",  # Set location mode for U.S. states
    color="ds_state_sector_headcount",  # Column with data to visualize
    scope="usa",  # Restrict to the U.S.
    title="Highest Employing Sector by State",  # Title for the map
    color_continuous_scale="Viridis",  # Color scale
    # labels={"value": "Value"},  # Label for the legend
)
fig.update_coloraxes(
    dict(
        colorbar=dict(
            title="Annual Salary",
        )
    )
)
fig.add_scattergeo(
    locations=top_sectors_empl["st"],
    locationmode="USA-states",
    text=top_sectors_empl["short_sector"],
    mode="text")

# Save the figure as an HTML file
fig.write_html("choropleth_map_empl.html")


os.system("open choropleth_map_empl.html")
python plotly plotly-python choropleth
1个回答
0
投票

您可以使用

marker
参数更改散点文本的颜色:

fig.add_scattergeo(
    locations=top_sectors_empl["st"],
    locationmode="USA-states",
    text=top_sectors_empl["short_sector"],
    marker=dict(color='white'),
    mode="text")
© www.soinside.com 2019 - 2024. All rights reserved.