Skip to content

Heatmap

heatmap() over named columns of a dataframe_mojo DataFrame (#743). Each argument names a column instead of holding the values.

Heatmap

Usage

from dataviz import heatmap
from dataviz import save
from dataviz import Theme

def main() raises:
    var day_names: List[String] = [
        "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
    ]
    var hour_names: List[String] = [
        "6am", "9am", "12pm", "3pm", "6pm", "9pm",
    ]
    # Illustrative support requests: weekday volume rises through the
    # workday, while weekends are quieter and peak later.
    var requests_by_day: List[List[Int]] = [
        [8, 24, 39, 46, 31, 14],
        [7, 27, 42, 49, 34, 16],
        [9, 29, 45, 52, 37, 18],
        [8, 26, 41, 48, 35, 17],
        [7, 23, 38, 44, 40, 24],
        [5, 11, 19, 27, 32, 25],
        [4, 9, 16, 23, 28, 21],
    ]

    var days = List[String]()
    var hours = List[String]()
    var requests = List[Int]()
    for day_i in range(len(day_names)):
        for hour_i in range(len(hour_names)):
            days.append(day_names[day_i])
            hours.append(hour_names[hour_i])
            requests.append(requests_by_day[day_i][hour_i])

    var c = heatmap(
        days,
        hours,
        requests,
        title="Illustrative Support Requests by Day and Hour",
        x_title="Day",
        y_title="Hour",
    )
    save(c, "docs/src/examples/out_heatmap.svg")

See Data shapes for shared input conventions.

Args:

  • df: The frame to read.
  • x: The string column for this channel.
  • y: The string column for this channel.
  • value: The numeric column for this channel.
  • theme: See the list overload.
  • width: See the list overload.
  • height: See the list overload.
  • title: See the list overload.
  • subtitle: See the list overload.
  • x_title: See the list overload.
  • y_title: See the list overload.

Related

Related charts: Image

Relevant API: heatmap