Skip to content

Area

1
area(Y);

example_area_1

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

int main() {
    using namespace matplot;

    std::vector<std::vector<double>> Y = {
        {1, 3, 1, 2}, {5, 2, 5, 6}, {3, 7, 3, 1}};

    auto f = gcf();
    f->width(f->width() * 2);

    subplot(1, 2, 0);
    area(Y);
    title("Stacked");

    subplot(1, 2, 1);
    area(Y, false);
    title("Not stacked");

    show();
    return 0;
}

More examples

example_area_2

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

int main() {
    using namespace matplot;

    std::vector<std::vector<double>> Y = {
        {1, 3, 1, 2}, {5, 2, 5, 6}, {3, 7, 3, 1}};

    auto f = gcf();
    f->width(f->width() * 2);

    subplot(1, 2, 0);
    area(Y, -4.);
    title("Stacked");

    subplot(1, 2, 1);
    area(Y, -4, false);
    title("Not stacked");

    show();
    return 0;
}

example_area_3

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

int main() {
    using namespace matplot;

    std::vector<std::vector<double>> Y = {
        {1, 3, 1, 2}, {5, 2, 5, 6}, {3, 7, 3, 1}};

    auto f = gcf();
    f->width(f->width() * 2);

    subplot(1, 2, 0);
    auto h1 = area(Y, -4.);
    h1[0]->line_style(":");
    h1[1]->line_style(":");
    h1[2]->line_style(":");
    h1[0]->face_color({0, 0, 0.25, 0.25});
    h1[1]->face_color({0, 0, 0.5, 0.5});
    h1[2]->face_color({0, 0, 0.75, 0.75});
    title("Stacked");

    subplot(1, 2, 1);
    auto h2 = area(Y, -4, false);
    h2[0]->line_style(":");
    h2[1]->line_style(":");
    h2[2]->line_style(":");
    h2[0]->face_color({0.2f, 0.f, 0.25f, 0.25f});
    h2[1]->face_color({0.2f, 0.f, 0.5f, 0.5f});
    h2[2]->face_color({0.2f, 0.f, 0.75f, 0.75f});
    title("Not stacked");

    show();
    return 0;
}

example_area_4

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

int main() {
    using namespace matplot;

    std::vector<std::vector<double>> Y = {
        {1, 3, 4, 0}, {2, 5, 4, 7}, {6, 4, 5, 3}};

    auto f = gcf();
    f->width(f->width() * 2);

    subplot(1, 2, 0);
    area(Y, -4.);
    title("Stacked");

    subplot(1, 2, 1);
    area(Y, -4, false);
    title("Not stacked");

    save("area_4.svg");

    show();
    return 0;
}