Skip to content

Y Tick Labels

1
yticklabels(ystrs);

example_yticklabels_1

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#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));

    ylim(ax2, {0, 1});
    yticks(ax2, {0, 0.25, .5, .75, 1});
    yticklabels(ax2, {"y=0", "1/4", "1/2", "3/4", "y=1"});

    show();
    return 0;
}

More examples

example_yticklabels_2

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

int main() {
    using namespace matplot;

    stem(iota(1, 10));

    yticks({1, 4, 6, 10});
    yticklabels({"A", "B", "C", "D"});

    show();
    return 0;
}

example_yticklabels_3

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

int main() {
    using namespace matplot;

    stem(iota(1, 10));

    yticks({1, 4, 6, 10});
    yticklabels({"A", "B", "C", "D"});

    yticks(automatic);
    yticklabels(automatic);

    show();
    return 0;
}

example_yticklabels_4

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

int main() {
    using namespace matplot;

    plot(rand(5, 5, 0, 1));
    yticklabels({});

    show();
    return 0;
}