Skip to content

Y Ticks

1
yticks(ys);

example_yticks_1

 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 pow(x, 2); });
    plot(x, y);
    yticks({0, 50, 100});
    yticklabels({"y=0", "y=50", "y=100"});

    show();
    return 0;
}

More examples

example_yticks_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 = linspace(-5, +5);
    auto y = transform(x, [](double x) { return pow(x, 2); });
    plot(x, y);
    yticks({0, 2, 4, 6, 8, 10, 15, 25});

    show();
    return 0;
}

example_yticks_3

 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 pow(x, 2.); });
    plot(x, y);
    yticks(iota(0, 25, 100));

    show();
    return 0;
}

example_yticks_4

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

int main() {
    using namespace matplot;

    auto x = linspace(0, 6 * pi);
    auto y = transform(x, [](double x) { return sin(x); });
    plot(x, y);
    xlim({0, 6 * pi});
    yticks(iota(-1, 1, 1));
    yticklabels({"min", "zero", "max"});

    show();
    return 0;
}

example_yticks_5

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

int main() {
    using namespace matplot;

    auto x = iota(0, 0.5, 3);
    auto y = rand(7, 0, 1);
    plot(x, y);
    auto ticks = iota(0, 0.25, 1.);
    yticks(ticks);
    xlabel("min");

    show();
    return 0;
}

example_yticks_6

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

int main() {
    using namespace matplot;

    stem(iota(1, 10));
    yticks({0, 5, 10});
    yticks(automatic);

    show();
    return 0;
}

example_yticks_7

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

int main() {
    using namespace matplot;

    tiledlayout(2, 1);
    auto ax1 = nexttile();
    plot(rand(3, 3, 0, 1));
    auto ax2 = nexttile();
    plot(rand(3, 3, 0, 1));
    yticks(iota(0, .2, 1));

    show();
    return 0;
}

example_yticks_8

 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);
    yticks({});

    show();
    return 0;
}