Skip to content

Heatmap

1
heatmap(data);

example_heatmap_1

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#include <matplot/matplot.h>

int main() {
    using namespace matplot;

    std::vector<std::vector<double>> data = {
        {45, 60, 32}, {43, 54, 76}, {32, 94, 68}, {23, 95, 58}};
    heatmap(data);

    show();
    return 0;
}

More examples

example_heatmap_2

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include <matplot/matplot.h>

int main() {
    using namespace matplot;

    std::vector<std::vector<double>> data = {
        {24, 10}, {10, 5}, {24, 16}, {8, 3}};
    heatmap(data);
    title("Count of SelfAssessedHealthStatus vs. Smoker");
    auto ax = gca();
    ax->x_axis().ticklabels({"false", "true"});
    ax->y_axis().ticklabels({"Excellent", "Fair", "Good", "Poor"});
    xlabel(ax, "Smoker");
    ylabel(ax, "SelfAssessedHealthStatus");

    show();
    return 0;
}

example_heatmap_3

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include <matplot/matplot.h>

int main() {
    using namespace matplot;

    std::vector<std::vector<double>> data = {
        {38.46, 39}, {39.7, 36.2}, {38.13, 38.88}, {33.88, 43}};
    heatmap(data);
    title("Mean of Age");
    auto ax = gca();
    ax->x_axis().ticklabels({"false", "true"});
    ax->y_axis().ticklabels({"Excellent", "Fair", "Good", "Poor"});
    xlabel(ax, "Smoker");
    ylabel(ax, "SelfAssessedHealthStatus");

    show();
    return 0;
}

example_heatmap_4

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include <matplot/matplot.h>

int main() {
    using namespace matplot;

    std::vector<std::vector<double>> data = {
        {45, 60, 32}, {43, 54, 76}, {32, 94, 68}, {23, 95, 58}};
    heatmap(data);
    title("T-Shirt Orders");
    auto ax = gca();
    ax->x_axis().ticklabels({"Small", "Medium", "Large"});
    ax->y_axis().ticklabels({"Green", "Red", "Blue", "Gray"});
    xlabel(ax, "Sizes");
    ylabel(ax, "Colors");

    show();
    return 0;
}

example_heatmap_5

 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
#include <matplot/matplot.h>

int main() {
    using namespace matplot;

    std::vector<std::vector<double>> data = {
        {12, 135, 20, 0, 127}, {0, 1, 0, 0, 1},  {19, 31, 81, 8, 49},
        {9, 18, 42, 2, 85},    {0, 5, 3, 0, 17}, {31, 143, 135, 6, 23},
        {32, 102, 54, 6, 7},   {5, 11, 4, 0, 4}, {16, 41, 13, 3, 22},
        {18, 70, 37, 1, 19}};
    heatmap(data);
    title("Count of Cause vs. Region");
    auto ax = gca();
    ax->x_axis().ticklabels(
        {"MidWest", "NorthEast", "SouthEast", "SouthWest", "West"});
    ax->y_axis().ticklabels(
        {"Attack", "Earthquake", "Energy emergency", "Equipment fault", "Fire",
         "Severe Storm", "Thunder Storm", "Unknown", "Wind", "Winter Storm"});
    xlabel(ax, "Region");
    ylabel(ax, "Cause");
    float w = ax->width();
    ax->width(w * 0.85f);
    ax->x_origin(ax->x_origin() + w * 0.1f);

    show();
    return 0;
}

example_heatmap_6

 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
#include <matplot/matplot.h>

int main() {
    using namespace matplot;

    std::vector<std::vector<double>> data = {
        {12, 135, 20, 0, 127}, {0, 1, 0, 0, 1},  {19, 31, 81, 8, 49},
        {9, 18, 42, 2, 85},    {0, 5, 3, 0, 17}, {31, 143, 135, 6, 23},
        {32, 102, 54, 6, 7},   {5, 11, 4, 0, 4}, {16, 41, 13, 3, 22},
        {18, 70, 37, 1, 19}};

    heatmap(data)->normalization(matrix::color_normalization::columns);

    title("Count of Cause vs. Region");
    auto ax = gca();
    ax->x_axis().ticklabels(
        {"MidWest", "NorthEast", "SouthEast", "SouthWest", "West"});
    ax->y_axis().ticklabels(
        {"Attack", "Earthquake", "Energy emergency", "Equipment fault", "Fire",
         "Severe Storm", "Thunder Storm", "Unknown", "Wind", "Winter Storm"});
    xlabel(ax, "Region");
    ylabel(ax, "Cause");
    float w = ax->width();
    ax->width(w * 0.85f);
    ax->x_origin(ax->x_origin() + w * 0.1f);

    show();
    return 0;
}

example_heatmap_7

 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
#include <matplot/matplot.h>

int main() {
    using namespace matplot;

    std::vector<std::vector<double>> data = {
        {12, 135, 20, 0, 127}, {0, 1, 0, 0, 1},  {19, 31, 81, 8, 49},
        {9, 18, 42, 2, 85},    {0, 5, 3, 0, 17}, {31, 143, 135, 6, 23},
        {32, 102, 54, 6, 7},   {5, 11, 4, 0, 4}, {16, 41, 13, 3, 22},
        {18, 70, 37, 1, 19}};

    heatmap(data)->normalization(matrix::color_normalization::rows);

    title("Count of Cause vs. Region");
    auto ax = gca();
    ax->x_axis().ticklabels(
        {"MidWest", "NorthEast", "SouthEast", "SouthWest", "West"});
    ax->y_axis().ticklabels(
        {"Attack", "Earthquake", "Energy emergency", "Equipment fault", "Fire",
         "Severe Storm", "Thunder Storm", "Unknown", "Wind", "Winter Storm"});
    xlabel(ax, "Region");
    ylabel(ax, "Cause");
    float w = ax->width();
    ax->width(w * 0.85f);
    ax->x_origin(ax->x_origin() + w * 0.1f);

    show();
    return 0;
}