:orphan:
:html_theme.sidebar_secondary.remove:
.. This document is auto-generated by the altair-gallery extension. Do not modify directly.
.. _gallery_line_chart_with_generator:
Line Chart with Sequence Generator
----------------------------------
This examples shows how to create multiple lines using the sequence generator.
.. altair-plot::
:remove-code:
import altair as alt
source = alt.sequence(start=0, stop=12.7, step=0.1, as_='x')
alt.Chart(source).mark_line().transform_calculate(
sin='sin(datum.x)',
cos='cos(datum.x)'
).transform_fold(
['sin', 'cos']
).encode(
x='x:Q',
y='value:Q',
color='key:N'
)
# 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
source = alt.sequence(start=0, stop=12.7, step=0.1, as_='x')
alt.Chart(source).mark_line().transform_calculate(
sin='sin(datum.x)',
cos='cos(datum.x)'
).transform_fold(
['sin', 'cos']
).encode(
x='x:Q',
y='value:Q',
color='key:N'
)
.. tab-item:: Attribute syntax
:sync: attribute
.. code:: python
import altair as alt
source = alt.sequence(start=0, stop=12.7, step=0.1, as_='x')
alt.Chart(source).mark_line().transform_calculate(
sin='sin(datum.x)',
cos='cos(datum.x)'
).transform_fold(
['sin', 'cos']
).encode(
x='x:Q',
y='value:Q',
color='key:N'
)
# No channel encoding options are specified in this chart
# so the code is the same as for the method-based syntax.