Rag*_*rok 7 python data-visualization vega-lite altair
我正在尝试在 Altair 中创建带有点标记的折线图。我正在使用Altair 文档中的多系列折线图示例,并尝试将其与Vega-Lite 文档中带有描边点标记的折线图示例结合起来。
我感到困惑的是如何处理“mark_line”参数。在 Vega 示例中,我需要使用“point”,然后将“filled”设置为 False。
"mark": {
"type": "line",
"point": {
"filled": false,
"fill": "white"
}
},
Run Code Online (Sandbox Code Playgroud)
我如何将其应用到 Altair 中?我发现将“point”设置为“True”或“{}”会添加一个点标记,但对如何让填充起作用感到困惑。
source = data.stocks()
alt.Chart(source).mark_line(
point=True
).encode(
x='date',
y='price',
color='symbol'
)
Run Code Online (Sandbox Code Playgroud)
您始终可以将原始 vega-lite 字典传递给 Altair 中的任何属性:
source = data.stocks()
alt.Chart(source).mark_line(
point={
"filled": False,
"fill": "white"
}
).encode(
x='date',
y='price',
color='symbol'
)
Run Code Online (Sandbox Code Playgroud)
或者您可以检查 的文档字符串mark_line()并发现它期望 point 为 anOverlayMarkDef()并使用 Python 包装器:
alt.Chart(source).mark_line(
point=alt.OverlayMarkDef(filled=False, fill='white')
).encode(
x='date',
y='price',
color='symbol'
)
Run Code Online (Sandbox Code Playgroud)
您可以将更多信息传递给 point 参数,类似于指定 vega-lite 的方式。
import altair as alt
from vega_datasets import data
source = data.stocks()
alt.Chart(source).mark_line(
point={
"filled": False,
"fill": "white"
}
).encode(
x='date',
y='price',
color='symbol'
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5028 次 |
| 最近记录: |