[英]Altair: Line Chart with Stroked Point Markers
I'm trying to create a line chart with point markers in Altair.我正在尝试在 Altair 中创建带有点标记的折线图。 I'm using the multi-series line chart example from Altair's documentation and trying to combine it with the line chart with stroked point markers example from Vega-Lite's documentation.我正在使用 Altair 文档中的多系列折线图示例,并尝试将其与 Vega-Lite 文档中带有描边点标记示例的折线图结合起来。
Where I'm confused is how to handle the 'mark_line' argument.我感到困惑的是如何处理“mark_line”参数。 From the Vega example, I need use "point" and then set "filled" to False.从 Vega 示例中,我需要使用“点”,然后将“填充”设置为 False。
"mark": {
"type": "line",
"point": {
"filled": false,
"fill": "white"
}
},
How would I apply that in Altair?我将如何在 Altair 中应用它? I figured out that setting 'point' to 'True' or '{}' added a point marker, but confused on how to get the fill to work.我发现将 'point' 设置为 'True' 或 '{}' 添加了一个点标记,但对如何让填充起作用感到困惑。
source = data.stocks()
alt.Chart(source).mark_line(
point=True
).encode(
x='date',
y='price',
color='symbol'
)
You can always pass a raw vega-lite dict to any property in Altair:您始终可以将原始 vega-lite dict 传递给 Altair 中的任何属性:
source = data.stocks()
alt.Chart(source).mark_line(
point={
"filled": False,
"fill": "white"
}
).encode(
x='date',
y='price',
color='symbol'
)
or you can check the docstring of mark_line()
and see that it expects point to be an OverlayMarkDef()
and use the Python wrappers:或者您可以检查mark_line()
的文档字符串,并看到它期望 point 是OverlayMarkDef()
并使用 Python 包装器:
alt.Chart(source).mark_line(
point=alt.OverlayMarkDef(filled=False, fill='white')
).encode(
x='date',
y='price',
color='symbol'
)
You can pass further information to the point parameter similar to how the vega-lite is specified.您可以将更多信息传递给点参数,类似于如何指定 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'
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.