Skip to content

Axes Object

1
auto ax1 = gca();

example_axes_1

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

int main() {
    using namespace matplot;
    auto ax1 = gca();
    axis({-100, +100, -30, +30});
    fplot(ax1, "3*cos(3*x) + tan(x)");

    show();
    return 0;
}

More examples

example_axes_2

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

int main() {
    using namespace matplot;
    auto ax1 = axes({0.1f, 0.1f, 0.7f, 0.7f});
    auto ax2 = axes({0.65f, 0.65f, 0.28f, 0.28f});

    auto [X, Y, Z] = peaks(20);
    contour(ax1, X, Y, Z);
    colorbar(ax1, off);
    surf(ax2, X, Y, Z);

    show();
    return 0;
}

example_axes_3

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

int main() {
    using namespace matplot;
    auto ax1 = axes({0.1f, 0.1f, 0.6f, 0.6f});
    auto ax2 = axes({0.35f, 0.35f, 0.6f, 0.6f});

    ax1->box(true);
    ax2->box(true);

    axes(ax1);
    auto x = linspace(0, 10);
    auto y = transform(x, [](double x) { return sin(x); });
    plot(x, y);

    show();
    return 0;
}