Skip to content

Adjust Axis

1
axis({xmin, xmax, ymin, ymax});

example_axis_1

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

int main() {
    using namespace matplot;

    fplot("sin(x)", "-o");
    axis({0, 2 * pi, -1.15, 1.5});

    show();
    return 0;
}

More examples

example_axis_2

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

int main() {
    using namespace matplot;

    fplot("sin(4*x)/exp(0.1*x)");
    axis({-10, +10, 0, inf});

    show();
    return 0;
}

example_axis_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;

    tiledlayout(2, 1);

    auto ax1 = nexttile();
    fplot(ax1, "sin(x)");

    auto ax2 = nexttile();
    fplot(ax2, "x < 5 ? sin(x) : -1");

    axis({ax1, ax2}, {0, 10, -1, 1});

    show();
    return 0;
}

example_axis_4

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

int main() {
    using namespace matplot;

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

    show();
    return 0;
}

example_axis_5

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

int main() {
    using namespace matplot;

    auto [X, Y, Z] = peaks();
    surf(X, Y, Z);
    axis(tight);

    show();
    return 0;
}

example_axis_6

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

int main() {
    using namespace matplot;

    auto c = eye(10);
    pcolor(c);
    colormap(palette::summer());
    axis(ij);

    show();
    return 0;
}

example_axis_7

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

int main() {
    using namespace matplot;

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

    auto y2 = transform(x, [](double x) { return 2 * sin(x); });
    hold(on);
    axis(manual);
    axis({0, 10, -1, +1});
    plot(x, y2);
    hold(off);

    show();
    return 0;
}

example_axis_8

 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
#include <iostream>
#include <matplot/matplot.h>
#include <set>
#include <thread>
#include <vector>

int main() {
    using namespace matplot;

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

    auto y2 = transform(x, [](double x) { return 2 * sin(x); });
    hold(on);
    axis(manual);
    axis({0, 10, -1, +1});
    plot(x, y2);
    hold(off);

    axis(automatic);

    show();
    return 0;
}