如何在选择期间动态更改Altair中轴的标签



不能在Altair 中动态更改连通图中的轴值

cor_data = alt.UrlData(url="https://raw.githubusercontent.com/keto08/covid-19/master/COVID19-UK/cor_data.csv")
df2 = alt.UrlData(url="https://raw.githubusercontent.com/keto08/covid-19/master/COVID19-UK/heatmap_scatter.csv")
var_sel_cor = alt.selection_single(fields=['variable', 'variable2'], clear=False, 
init={'variable': 'value1', 'variable2': 'value2'})
base = alt.Chart(cor_data,title="Corellation Among Inputs and Outputs").encode(
x=alt.X('variable2:O',title=""),
y=alt.Y('variable:O',title="")    
)
text = base.mark_text().encode(
text='correlation_label:O',
color=alt.condition(
alt.datum.correlation > 0.5, 
alt.value('white'),
alt.value('black')
)
)
cor_plot = base.mark_rect().encode(alt.Color('correlation:Q',
scale=alt.Scale(
scheme='redblue',
domain=[-1, 0, 1],
type='linear'))).add_selection(var_sel_cor)
zoom = alt.selection_interval(
bind='scales',
on="[mousedown[!event.shiftKey], mouseup] > mousemove",
translate="[mousedown[!event.shiftKey], mouseup] > mousemove!",
)
selection = alt.selection_interval(
on="[mousedown[event.shiftKey], mouseup] > mousemove",
translate="[mousedown[event.shiftKey], mouseup] > mousemove!",
)
scat_plot = alt.Chart(df2).transform_filter(
var_sel_cor
).mark_circle(opacity=0.5).encode(
x=alt.X('value1:Q'), 
y=alt.Y('value2:Q'),
size=alt.Size('population:Q',legend=alt.Legend(padding=35,offset=5)),
).add_selection(zoom,selection)
alt.data_transformers.enable('default', max_rows=None)
alt.hconcat((cor_plot + text).properties(width=500, height=500), scat_plot.properties(width=350, height=350)).resolve_scale(color='independent')

这个代码给我热图与连接散点图

我想动态更改"连接散点图"的轴标签(x轴和y轴(。有人能建议我怎么做吗?

这在Altair中是不可能的。一种解决方法是使用mark_text创建一个具有正确标签的单独图表(如"我可以将高度轴标题转换为链接吗?"(并缩小间距。我认为在Vega Lite中使用新的parameters是可能的,所以如果你在那里搜索问题跟踪器,你可能会发现一些东西。如果是,它将在Altair更新到最新的Vega Lite版本时可用,否则您可以建议将其作为Vega Lite的功能。我认为您的示例是一个很好的用例,说明此功能何时会有所帮助。

相关问题

最新更新