:orphan:
:html_theme.sidebar_secondary.remove:
.. This document is auto-generated by the altair-gallery extension. Do not modify directly.
.. _gallery_line_chart_with_datum:
Line Chart with Datum
---------------------------------
An example of using ``datum`` to highlight certain values, including a ``DateTime`` value.
This is adapted from two corresponding Vega-Lite Examples:
`Highlight a Specific Value `_.
.. altair-plot::
:remove-code:
import altair as alt
from vega_datasets import data
source = data.stocks()
lines = (
alt.Chart(source)
.mark_line()
.encode(x="date", y="price", color="symbol")
)
xrule = (
alt.Chart()
.mark_rule(color="cyan", strokeWidth=2)
.encode(x=alt.datum(alt.DateTime(year=2006, month="November")))
)
yrule = (
alt.Chart().mark_rule(strokeDash=[12, 6], size=2).encode(y=alt.datum(350))
)
lines + yrule + xrule
# No channel encoding options are specified in this chart
# so the code is the same as for the method-based syntax.
.. tab-set::
.. tab-item:: Method syntax
:sync: method
.. code:: python
import altair as alt
from vega_datasets import data
source = data.stocks()
lines = (
alt.Chart(source)
.mark_line()
.encode(x="date", y="price", color="symbol")
)
xrule = (
alt.Chart()
.mark_rule(color="cyan", strokeWidth=2)
.encode(x=alt.datum(alt.DateTime(year=2006, month="November")))
)
yrule = (
alt.Chart().mark_rule(strokeDash=[12, 6], size=2).encode(y=alt.datum(350))
)
lines + yrule + xrule
.. tab-item:: Attribute syntax
:sync: attribute
.. code:: python
import altair as alt
from vega_datasets import data
source = data.stocks()
lines = (
alt.Chart(source)
.mark_line()
.encode(x="date", y="price", color="symbol")
)
xrule = (
alt.Chart()
.mark_rule(color="cyan", strokeWidth=2)
.encode(x=alt.datum(alt.DateTime(year=2006, month="November")))
)
yrule = (
alt.Chart().mark_rule(strokeDash=[12, 6], size=2).encode(y=alt.datum(350))
)
lines + yrule + xrule
# No channel encoding options are specified in this chart
# so the code is the same as for the method-based syntax.