I'm trying to create a line chart with point markers in 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.
Where I'm confused is how to handle the 'mark_line' argument. From the Vega example, I need use "point" and then set "filled" to False.
"mark": {
"type": "line",
"point": {
"filled": false,
"fill": "white"
}
},
How would I apply that in Altair? I figured out that setting 'point' to 'True' or '{}' added a point marker, but confused on how to get the fill to work.
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:
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:
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.
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'
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With