Skip to content

Mesh with Contour

1
meshc(X, Y, Z);

example_meshc_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, .125, +3));
    auto Z = peaks(X, Y);
    meshc(X, Y, Z);

    show();
    return 0;
}

More examples

example_meshc_2

 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; });
    meshc(X, Y, Z, C);
    colorbar();

    show();
    return 0;
}

example_meshc_3

 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); });
    auto sc = meshc(X, Y, Z);
    sc->edge_color("r");
    sc->contour_line_spec().color("b");

    show();
    return 0;
}