Skip to content

Y Limits

1
ylim({ymin,ymax});

example_ylim_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);
    ylim({-2, +2});

    show();
    return 0;
}

More examples

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

    show();
    return 0;
}

example_ylim_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, 10, 1000);
    auto y = transform(x, [](double x) { return sin(10 * x) * exp(.5 * x); });

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

    auto ax2 = nexttile();
    plot(ax2, x, y);
    ylim(ax2, {-10, 10});

    show();
    return 0;
}

example_ylim_4

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

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

    show();
    return 0;
}

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

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

    ylim(automatic);

    show();
    return 0;
}

example_ylim_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 yl = ylim();
    std::cout << "yl[0]: " << yl[0] << std::endl;
    std::cout << "yl[1]: " << yl[1] << std::endl;

    show();
    return 0;
}