【发布时间】: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