Skip to content

Ribbon

1
ribbon(X, Y, Z);

example_ribbon_1

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

int main() {
    using namespace matplot;
    auto [X, Y] = meshgrid(iota(-3, .5, 3), iota(-3, .1, 3));
    auto Z = peaks(X, Y);
    ribbon(X, Y, Z);

    show();
    return 0;
}

More examples

example_ribbon_2

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

int main() {
    using namespace matplot;
    auto [X, Y] = meshgrid(iota(-3, .5, 3), iota(-3, .1, 3));
    auto Z = peaks(X, Y);
    auto [FX, FY] = gradient(Z);
    (void) FY;
    ribbon(X, Y, Z, FX, 1.0);
    colorbar();

    show();
    return 0;
}

example_ribbon_3

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

int main() {
    using namespace matplot;
    auto [X, Y] = meshgrid(iota(-5, .5, 5));
    auto Z = transform(
        X, Y, [](double x, double y) { return y * sin(x) - x * cos(y); });
    ribbon(X, Y, Z)->edge_color("green").face_alpha(0.5);

    show();
    return 0;
}

example_ribbon_4

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

int main() {
    using namespace matplot;

    auto rastrigin = [](double x, double y) {
        return 10 * 2 + pow(x, 2) - 10 * cos(2 * pi * x) + pow(y, 2) -
               10 * cos(2 * pi * y);
    };

    auto [X, Y] = meshgrid(iota(-5, 1., 5), iota(-5, .1, 5));
    auto Z = transform(X, Y, rastrigin);
    ribbon(X, Y, Z)->face_alpha(0.8f);

    show();
    return 0;
}