列表中的Altair注释

2024-09-28 17:31:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个像这样的图:original

并希望添加注释,使其看起来像这样: enter image description here

有没有办法从带有注释文本的数据框中添加这些注释

annotations = [['2017-08-27 00:15:00',4, 'Fight begins'],
           ['2017-08-27 00:22:00',5, 'McGregor does OK \nin the early rounds'],
           ['2017-08-27 00:53:00',4, 'Mayweather takes \nover and wins by \nTKO']]
           a_df = pd.DataFrame(annotations, columns=['date','count','note'])

Tags: the数据文本okannotations办法takesearly
1条回答
网友
1楼 · 发布于 2024-09-28 17:31:07

在牵牛星中,并没有任何自动的方法可以做到这一点

可以添加一个文本层;例如:

text = alt.Chart(annotations).mark_text().encode(
  x='date:Q',
  y='count:N',
  text='note:N',
)

chart = lines + text

但这只是在指定位置绘制文本块;它不会添加注释箭头或执行任何类型的自动放置、换行或避免碰撞。在当前版本的Altair中,您必须手动执行此操作

相关问题 更多 >