Skip to content

View

1
view(az, el);

example_view_1

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

int main() {
    using namespace matplot;

    auto [x, y, z] = peaks();
    surf(x, y, z);
    xlabel("x");
    ylabel("y");
    zlabel("z");
    view(90, 0);

    show();
    return 0;
}

More examples

example_view_2

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

int main() {
    using namespace matplot;

    auto [x, y, z] = peaks();
    surf(x, y, z);
    xlabel("x");
    ylabel("y");
    zlabel("z");
    view(2);

    show();
    return 0;
}

example_view_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
#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); });
    surf(x, y, z);
    xlabel("x");
    ylabel("y");
    zlabel("z");

    auto [az, el] = view();
    std::cout << "az: " << az << std::endl;
    std::cout << "el: " << el << std::endl;

    auto [naz, nel] = view(-5, -2, 5);
    std::cout << "naz: " << naz << std::endl;
    std::cout << "nel: " << nel << std::endl;

    show();
    return 0;
}

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

int main() {
    using namespace matplot;

    auto t = iota(0, pi / 20, 10 * pi);
    auto xt1 = transform(t, [](double t) { return sin(t); });
    auto yt1 = transform(t, [](double t) { return cos(t); });
    tiledlayout(1, 2);

    auto ax1 = nexttile();
    plot3(ax1, xt1, yt1, t);
    xlabel("x");
    ylabel("y");
    zlabel("z");

    auto ax2 = nexttile();
    plot3(ax2, xt1, yt1, t);
    xlabel("x");
    ylabel("y");
    zlabel("z");
    view(ax2, 90, 0);

    show();
    return 0;
}

example_view_5

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

int main() {
    using namespace matplot;

    auto [x, y, z] = peaks(20);
    auto s = surf(x, y, z);
    xlabel("x-axis");
    ylabel("y-axis");
    zlabel("z-axis");

    rotate(20, 30);

    show();
    return 0;
}

example_view_6

 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 ackley = [](double x, double y) {
        return -20 * exp(-0.2 * sqrt(0.5 * (pow(x, 2) + pow(y, 2)))) -
               exp(0.5 * (cos(2 * pi * x) + cos(2 * pi * y))) + exp(1) + 20;
    };

    gcf()->width(gcf()->width() * 2);
    subplot(1, 2, 0);
    fsurf(ackley)->lighting(true).primary(0.7f).specular(0.9f);
    subplot(1, 2, 1);
    fsurf(ackley);
    rotate(20, 30);

    show();
    return 0;
}