File: lasagna_plot.py

package info (click to toggle)
python-altair 5.0.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,952 kB
  • sloc: python: 25,649; sh: 14; makefile: 6
file content (33 lines) | stat: -rw-r--r-- 796 bytes parent folder | download | duplicates (2)
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
"""
Lasagna Plot (Dense Time-Series Heatmap)
----------------------------------------
"""
# category: tables
import altair as alt
from vega_datasets import data

source = data.stocks()

color_condition = alt.condition(
    "month(datum.value) == 1 && date(datum.value) == 1",
    alt.value("black"),
    alt.value(None),
)

alt.Chart(source, width=300, height=100).transform_filter(
    alt.datum.symbol != "GOOG"
).mark_rect().encode(
    x=alt.X(
        "yearmonthdate(date):O",
        axis=alt.Axis(
            format="%Y",
            labelAngle=0,
            labelOverlap=False,
            labelColor=color_condition,
            tickColor=color_condition,
        ),
        title="Time",
    ),
    y=alt.Y("symbol:N", title=None),
    color=alt.Color("sum(price)", title="Price"),
)