Skip to content

Surface with Contour

1
surfc(X, Y, Z);

example_surfc_1

 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(linspace(-5, +5, 70), linspace(-5, +5, 70));
    auto Z = transform(X, Y, [](double x, double y) {
        return 10 * 2 + pow(x, 2) - 10 * cos(2 * pi * x) + pow(y, 2) -
               10 * cos(2 * pi * y);
    });
    surfc(X, Y, Z);

    show();
    return 0;
}

More examples

example_surfc_2

 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(1, .5, 10), iota(1, 20));
    auto Z =
        transform(X, Y, [](double x, double y) { return sin(x) + cos(y); });
    auto s = surfc(X, Y, Z);

    show();
    return 0;
}

example_surfc_3

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

int main() {
    using namespace matplot;
    auto [X, Y] = meshgrid(iota(-3, .125, 3));
    auto Z = peaks(X, Y);
    auto C = transform(X, Y, [](double x, double y) { return x * y; });
    surfc(X, Y, Z, C);
    colorbar();

    show();
    return 0;
}

example_surfc_4

 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(-5, .5, 5));
    auto Z = transform(
        X, Y, [](double x, double y) { return y * sin(x) - x * cos(y); });

    surfc(X, Y, Z)->edge_color({0, 1, 0, 0});
    colormap({{0, 0, 1}});

    show();
    return 0;
}