有没有办法将标签添加到状态图中?例如,将百分比直接显示在各个状态上,而不是只能通过工具提示查看它们?
我不确定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'
)

发布于 2020-12-10 05:57:11
Altair没有用于在地理区域上显示标签的内置功能。也就是说,如果您有一个数据帧,其中的列包含您想要显示的纬度、经度和文本,则可以使用mark_text()和latitude/longitude编码来执行此操作;您可以在Altair的文档中找到一个这样的示例:https://altair-viz.github.io/gallery/london_tube.html
如果你想要的是一个具有内置功能的可视化工具,可以计算地理区域的质心并在这些点上绘制标签,那么Altair可能不是你想要的。
https://stackoverflow.com/questions/65222362
复制相似问题