Altair:带有描边点标记的折线图
Altair: Line Chart with Stroked Point Markers
我正在尝试在 Altair 中创建带有点标记的折线图。我正在使用 Vega-Lite 文档中的 multi-series line chart example from Altair's documentation and trying to combine it with the line chart with stroked point markers example。
我感到困惑的是如何处理 'mark_line' 参数。在 Vega 示例中,我需要使用 "point" 然后将 "filled" 设置为 False。
"mark": {
"type": "line",
"point": {
"filled": false,
"fill": "white"
}
},
我将如何在 Altair 中应用它?我发现将 'point' 设置为 'True' 或“{}”会添加一个点标记,但对如何使填充工作感到困惑。
source = data.stocks()
alt.Chart(source).mark_line(
point=True
).encode(
x='date',
y='price',
color='symbol'
)
您可以将更多信息传递给点参数,类似于指定 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'
)
您始终可以将原始 vega-lite dict 传递给 Altair 中的任何 属性:
source = data.stocks()
alt.Chart(source).mark_line(
point={
"filled": False,
"fill": "white"
}
).encode(
x='date',
y='price',
color='symbol'
)
或者你可以检查 mark_line()
的文档字符串,看看它期望点是一个 OverlayMarkDef()
并使用 Python 包装器:
alt.Chart(source).mark_line(
point=alt.OverlayMarkDef(filled=False, fill='white')
).encode(
x='date',
y='price',
color='symbol'
)
我正在尝试在 Altair 中创建带有点标记的折线图。我正在使用 Vega-Lite 文档中的 multi-series line chart example from Altair's documentation and trying to combine it with the line chart with stroked point markers example。
我感到困惑的是如何处理 'mark_line' 参数。在 Vega 示例中,我需要使用 "point" 然后将 "filled" 设置为 False。
"mark": {
"type": "line",
"point": {
"filled": false,
"fill": "white"
}
},
我将如何在 Altair 中应用它?我发现将 'point' 设置为 'True' 或“{}”会添加一个点标记,但对如何使填充工作感到困惑。
source = data.stocks()
alt.Chart(source).mark_line(
point=True
).encode(
x='date',
y='price',
color='symbol'
)
您可以将更多信息传递给点参数,类似于指定 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'
)
您始终可以将原始 vega-lite dict 传递给 Altair 中的任何 属性:
source = data.stocks()
alt.Chart(source).mark_line(
point={
"filled": False,
"fill": "white"
}
).encode(
x='date',
y='price',
color='symbol'
)
或者你可以检查 mark_line()
的文档字符串,看看它期望点是一个 OverlayMarkDef()
并使用 Python 包装器:
alt.Chart(source).mark_line(
point=alt.OverlayMarkDef(filled=False, fill='white')
).encode(
x='date',
y='price',
color='symbol'
)