Skip to content

X Limits

1
xlim({xmin,xmax});

example_xlim_1

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#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);
    xlim({0, 5});

    show();
    return 0;
}

More examples

example_xlim_2

 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);
    xlim({0, inf});

    show();
    return 0;
}

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

int main() {
    using namespace matplot;

    tiledlayout(2, 1);

    auto x = linspace(0, 5, 1000);
    auto y = transform(x, [](double x) { return sin(100 * x) / exp(x); });

    auto ax1 = nexttile();
    plot(ax1, x, y);

    auto ax2 = nexttile();
    plot(ax2, x, y);
    xlim(ax2, {0, 1});

    show();
    return 0;
}

example_xlim_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
#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);

    xlim(manual);
    xlim({0, 10});
    hold(on);
    auto x2 = transform(x, [](double x) { return 2 * x; });
    auto y2 = transform(y, [](double y) { return 2 * y; });
    plot(x2, y2);
    hold(off);

    show();
    return 0;
}

example_xlim_5

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

    xlim(manual);
    xlim({0, 10});
    hold(on);
    auto x2 = transform(x, [](double x) { return 2 * x; });
    auto y2 = transform(y, [](double y) { return 2 * y; });
    plot(x2, y2);
    hold(off);
    xlim(automatic);

    show();
    return 0;
}

example_xlim_6

 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 x = randn(50, 0, 1);
    auto y = randn(50, 0, 1);
    scatter(x, y);

    auto xl = xlim();
    std::cout << "xl[0]: " << xl[0] << std::endl;
    std::cout << "xl[1]: " << xl[1] << std::endl;

    show();
    return 0;
}