【问题标题】:Adding labels to altair choropleth maps向 altair 等值线地图添加标签
【发布时间】:2020-12-09 17:58:19
【问题描述】:

有没有办法给状态图添加标签?例如,要直接在各个状态上显示百分比,而不是只能通过工具提示查看它们?

我不确定 Altair 是否有此选项,或者我是否需要查看其他软件包(plotly、folium 等)并进行一些分层以获得这些结果。

import altair as alt
from vega_datasets import data
states = alt.topo_feature(data.us_10m.url, 'states')
variable_list = ['Percentage', 'State Name', 'state_id']

alt.Chart(states).mark_geoshape(stroke='white', width=0.01).encode(
    color=alt.Color('Percentage:Q', title='Positive NFB', legend=alt.Legend(format=".0%"), scale=alt.Scale(scheme='yellowgreenblue', domain=[0, 1])),
    tooltip=['State Name:N', alt.Tooltip('Percentage:Q', format='.0%')]).properties(title="Percentage of People in Households with Positive NFB"
).transform_lookup(
lookup='id',
from_=alt.LookupData(states_positive_NFB, 'state_id', variable_list)
).properties(
width=500,
height=300
).project(
type='albersUsa'
)

【问题讨论】:

    标签: label altair choropleth


    【解决方案1】:

    Altair 没有用于在地理区域上显示标签的内置功能。也就是说,如果您有一个数据框,其中的列包含您想要显示的纬度、经度和文本,您可以使用mark_text()latitude/longitude 编码来实现;您可以在 Altair 的文档中找到这样的示例:https://altair-viz.github.io/gallery/london_tube.html

    如果您想要一个可视化工具,它具有用于计算地理区域的质心并在这些点绘制标签的内置功能,那么 Altair 可能不是您想要的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-02
      • 2020-04-01
      • 2020-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多