您可以通过两个步骤在 Altair 图中获得注释:
mark_text()指定标注的位置,字体大小等。transform_filter()来自datum于选择需要注释的点(数据子集)。注意行from altair import datum.代码:
import altair as alt
from vega_datasets import data
alt.renderers.enable('notebook')
from altair import datum #Needed for subsetting (transforming data)
iris = data.iris()
points = alt.Chart(iris).mark_point().encode(
x='petalLength',
y='petalWidth',
color='species')
annotation = alt.Chart(iris).mark_text(
align='left',
baseline='middle',
fontSize = 20,
dx = 7
).encode(
x='petalLength',
y='petalWidth',
text='petalLength'
).transform_filter(
(datum.petalLength >= 5.1) & (datum.petalWidth < 1.6)
)
points + annotation
Run Code Online (Sandbox Code Playgroud)
这些是静态注释。您还可以通过绑定selections到绘图来获得交互式注释。
| 归档时间: |
|
| 查看次数: |
5001 次 |
| 最近记录: |