File: trail.rst

package info (click to toggle)
python-altair 5.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,952 kB
  • sloc: python: 25,649; sh: 14; makefile: 5
file content (70 lines) | stat: -rw-r--r-- 2,182 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
.. currentmodule:: altair

.. _user-guide-trail-marks:

Trail
~~~~~
The ``trail`` mark represents the data points stored in a field with a line connecting all of these points. Trail is similar to the ``line`` mark but a trail can have variable widths determined by backing data. Unlike lines, trails do not support different interpolation methods and use ``fill`` (not ``stroke``) for their color. Trail marks are useful if you want to draw lines with changing size to reflect the underlying data.

Trail Mark Properties
---------------------
A ``trail`` mark definition can contain any :ref:`standard mark properties <mark-properties>`
and the following special properties:

.. altair-object-table:: altair.MarkDef
   :properties: orient

Examples
--------
Line Chart with Varying Size
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. altair-plot::
    import altair as alt
    from vega_datasets import data

    source = data.stocks()

    alt.Chart(source).mark_trail().encode(
        x="date",
        y="price",
        color="symbol",
        size="price",
    )

Comet Chart Showing Changes Between Two States
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. altair-plot::
    import altair as alt
    from vega_datasets import data

    alt.Chart(data.barley.url).transform_pivot(
        "year",
        value="yield",
        groupby=["variety", "site"]
    ).transform_fold(
        ["1931", "1932"],
        as_=["year", "yield"]
    ).transform_calculate(
        calculate="datum['1932'] - datum['1931']",
        as_="delta"
    ).mark_trail().encode(
        alt.X("year:O").title(None),
        alt.Y("variety:N").title("Variety"),
        alt.Size("yield:Q")
            .scale(range=[0, 12])
            .legend(values=[20, 60])
            .title("Barley Yield (bushels/acre)"),
        alt.Color("delta:Q")
            .scale(domainMid=0)
            .title("Yield Delta (%)"),
        alt.Tooltip(["year:O", "yield:Q"]),
        alt.Column("site:N").title("Site"),
    ).configure_legend(
        orient='bottom',
        direction='horizontal'
    ).configure_view(
        stroke=None
    ).properties(
        title="Barley Yield comparison between 1932 and 1931"
    )