Skip to content

Grid Background

1
grid(on);

example_grid_1

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

int main() {
    using namespace matplot;

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

    show();
    return 0;
}

More examples

example_grid_2

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

int main() {
    using namespace matplot;

    auto [X, Y, Z] = peaks();
    surf(X, Y, Z);
    grid(off);
    box(off);

    show();
    return 0;
}

example_grid_3

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

int main() {
    using namespace matplot;

    auto x = linspace(0, 10);
    auto y = transform(x, [](double x) { return sin(x); });
    plot(x, y);
    grid(on);
    gca()->minor_grid(true);

    show();
    return 0;
}

example_grid_4

 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 x = linspace(0, 10);
    auto y1 = transform(x, [](double x) { return sin(x); });
    auto y2 = transform(x, [](double x) { return sin(3 * x); });

    tiledlayout(2, 1);
    auto ax1 = nexttile();
    plot(ax1, x, y1);

    auto ax2 = nexttile();
    plot(ax2, x, y2);
    grid(ax2, on);

    show();
    return 0;
}