BBohua ZhanAdd more docs.
4be840a1创建于 2022年9月16日历史提交

Heatmap

Plot heatmap, which uses different shades of color to illustrate magnitude of each value in a matrix.

Examples

  1. Basic heatmap.

::

let data = matrix([
    [45.0, 60.0, 32.0],
    [43.0, 54.0, 76.0],
    [32.0, 94.0, 68.0],
    [23.0, 95.0, 58.0]
])

heatmap(data)

Result:

.. image:: ../../../tests/imgs/heatmap/heatmap_1.png :align: center :width: 360

  1. Heatmap with title and labels.

::

let data = matrix([
    [24.0, 10.0],
    [10.0, 5.0],
    [24.0, 16.0],
    [8.0, 3.0]
])

heatmap(data)
title("Conut of SelfAssessedHealthStatus vs. Smoker")
xticklabels(["false", "true"])
yticklabels(["Excellent", "Fair", "Good", "Poor"])
xlabel("Smoker")
ylabel("SelfAssessedHealthStatus")

Result:

.. image:: ../../../tests/imgs/heatmap/heatmap_2.png :align: center :width: 360

  1. Heatmap with custom width.

::

let data = matrix([
    [12.0, 135.0, 20.0, 0.0, 127.0],
    [0.0, 1.0, 0.0, 0.0, 1.0],
    [19.0, 31.0, 81.0, 8.0, 49.0],
    [9.0, 18.0, 42.0, 2.0, 85.0],
    [0.0, 5.0, 3.0, 0.0, 17.0],
    [31.0, 143.0, 135.0, 6.0, 23.0],
    [32.0, 102.0, 54.0, 6.0, 7.0],
    [5.0, 11.0, 4.0, 0.0, 4.0],
    [16.0, 41.0, 13.0, 3.0, 22.0],
    [18.0, 70.0, 37.0, 1.0, 19.0]
])

heatmap(data)
title("Count of Cause vs. Region")
let ax = gca()
xticklabels(["MidWest", "NorthEast", "SouthEast", "SouthWest", "West"])
yticklabels(["Attack", "Earthquake", "Energy emergency", "Equipment fault", "Fire",
     "Severe Storm", "Thunder Storm", "Unknown", "Wind", "Winter Storm"])
xlabel("Region")
ylabel("Cause")
var w = ax.width()
ax.width(w * 0.85)
ax.x_origin(ax.x_origin() + w * 0.1)

Result:

.. image:: ../../../tests/imgs/heatmap/heatmap_5.png :align: center :width: 360

  1. Heatmap with different normalization methods.

::

let data = matrix([
    [12.0, 135.0, 20.0, 0.0, 127.0],
    [0.0, 1.0, 0.0, 0.0, 1.0],
    [19.0, 31.0, 81.0, 8.0, 49.0],
    [9.0, 18.0, 42.0, 2.0, 85.0],
    [0.0, 5.0, 3.0, 0.0, 17.0],
    [31.0, 143.0, 135.0, 6.0, 23.0],
    [32.0, 102.0, 54.0, 6.0, 7.0],
    [5.0, 11.0, 4.0, 0.0, 4.0],
    [16.0, 41.0, 13.0, 3.0, 22.0],
    [18.0, 70.0, 37.0, 1.0, 19.0]
])

heatmap(data).normalization(color_normalization.columns)
title("Count of Cause vs. Region")
let ax = gca()
xticklabels(["MidWest", "NorthEast", "SouthEast", "SouthWest", "West"])
yticklabels(["Attack", "Earthquake", "Energy emergency", "Equipment fault", "Fire",
     "Severe Storm", "Thunder Storm", "Unknown", "Wind", "Winter Storm"])
xlabel("Region")
ylabel("Cause")
var w = ax.width()
ax.width(w * 0.85)
ax.x_origin(ax.x_origin() + w * 0.1)

Result:

.. image:: ../../../tests/imgs/heatmap/heatmap_6.png :align: center :width: 360

  1. Heatmap with different normalization methods.

::

let data = matrix([
    [12.0, 135.0, 20.0, 0.0, 127.0],
    [0.0, 1.0, 0.0, 0.0, 1.0],
    [19.0, 31.0, 81.0, 8.0, 49.0],
    [9.0, 18.0, 42.0, 2.0, 85.0],
    [0.0, 5.0, 3.0, 0.0, 17.0],
    [31.0, 143.0, 135.0, 6.0, 23.0],
    [32.0, 102.0, 54.0, 6.0, 7.0],
    [5.0, 11.0, 4.0, 0.0, 4.0],
    [16.0, 41.0, 13.0, 3.0, 22.0],
    [18.0, 70.0, 37.0, 1.0, 19.0]
])

heatmap(data).normalization(color_normalization.rows)
title("Count of Cause vs. Region")
let ax = gca()
xticklabels(["MidWest", "NorthEast", "SouthEast", "SouthWest", "West"])
yticklabels(["Attack", "Earthquake", "Energy emergency", "Equipment fault", "Fire",
     "Severe Storm", "Thunder Storm", "Unknown", "Wind", "Winter Storm"])
xlabel("Region")
ylabel("Cause")
var w = ax.width()
ax.width(w * 0.85)
ax.x_origin(ax.x_origin() + w * 0.1)

Result:

.. image:: ../../../tests/imgs/heatmap/heatmap_7.png :align: center :width: 360

Methods

============================== =============================== Method Description ============================== =============================== heatmap 1 method Plot a heatmap ============================== ===============================

Description

.. function:: heatmap(data)

:param data: Matrix<Float64>

Plot heatmap with given data