Skip to content

Hold

1
hold(on);

example_hold_1

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

int main() {
    using namespace matplot;

    auto x = linspace(-pi, pi);
    auto y1 = transform(x, [](double x) { return sin(x); });
    plot(x, y1);

    hold(on);
    auto y2 = transform(x, [](double x) { return cos(x); });
    plot(x, y2);
    hold(off);

    show();
    return 0;
}

More examples

example_hold_2

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

int main() {
    using namespace matplot;

    auto x = linspace(-pi, pi);
    auto y1 = transform(x, [](double x) { return sin(x); });
    plot(x, y1);

    hold(on);
    auto y2 = transform(x, [](double x) { return cos(x); });
    plot(x, y2);
    hold(off);

    auto y3 = transform(x, [](double x) { return sin(2 * x); });
    plot(x, y3);

    show();
    return 0;
}

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

int main() {
    using namespace matplot;

    auto x = linspace(0, 10);

    auto y1 = transform(x, [](double x) { return sin(x); });
    auto y2 = transform(x, [](double x) { return cos(x); });

    tiledlayout(2, 1);

    auto ax1 = nexttile();
    plot(ax1, x, y1);

    auto ax2 = nexttile();
    plot(ax2, x, y2);

    hold(ax1, on);
    auto y3 = transform(x, [](double x) { return sin(2 * x); });
    plot(ax1, x, y3);
    hold(ax1, off);

    show();
    return 0;
}

example_hold_4

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

int main() {
    using namespace matplot;

    tiledlayout(1, 2);
    auto ax1 = nexttile();
    auto ax2 = nexttile();

    plot(ax1, {0, 1, 0, 1});
    auto s1 = scatter(ax2, rand(10, 0, 1), rand(10, 0, 1));
    s1->marker_face(true);

    hold({ax1, ax2}, on);
    plot(ax1, {.5, .2, .5, .2});
    auto s2 = scatter(ax2, rand(10, 0, 1), rand(10, 0, 1));
    s2->marker_face(true);

    show();
    return 0;
}