Skip to content

X Tick Labels

1
xticklabels(xstrs);

example_xticklabels_1

 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;

    tiledlayout(2, 1);
    auto ax1 = nexttile();
    plot(rand(3, 3, 0, 1));
    auto ax2 = nexttile();
    plot(rand(3, 3, 0, 1));
    xticks({1, 2, 3});
    xticklabels({"one", "two", "three"});

    show();
    return 0;
}

More examples

example_xticklabels_2

 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));
    xticks({1, 4, 6, 10});
    xticklabels({"A", "B", "C", "D"});

    show();
    return 0;
}

example_xticklabels_3

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

int main() {
    using namespace matplot;

    stem(iota(1, 10));
    xticks({1, 4, 6, 10});
    xticklabels({"A", "B", "C", "D"});
    xticks(automatic);
    xticklabels(automatic);

    show();
    return 0;
}

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

    show();
    return 0;
}