Skip to content

Y Label

1
ylabel(str);

example_ylabel_1

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

int main() {
    using namespace matplot;
    auto x = transform(iota(1, 10), [](double x) { return pow(x, 2); });
    plot(x);
    ylabel("Population");

    show();
    return 0;
}

More examples

example_ylabel_2

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

int main() {
    using namespace matplot;
    auto x = transform(iota(1, 10), [](double x) { return pow(x, 2); });
    plot(x);
    ylabel("2010 Population\\nin Years");

    show();
    return 0;
}

example_ylabel_3

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

int main() {
    using namespace matplot;
    auto x = linspace(-2 * pi, +2 * pi);
    auto y = transform(x, [](double x) { return sin(x); });
    plot(x, y);
    ylabel("-2π ≤ x ≤ 2π");

    show();
    return 0;
}

example_ylabel_4

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

int main() {
    using namespace matplot;
    auto x = transform(iota(1, 10), [](double x) { return pow(x, 2); });
    plot(x);
    int year = 2014;
    ylabel("Population for Year " + num2str(year));

    show();
    return 0;
}

example_ylabel_5

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

int main() {
    using namespace matplot;
    auto t = linspace(0, 1);
    auto y = transform(t, [](double t) { return exp(t); });
    plot(t, y);
    ylabel("t_{seconds}");
    ylabel("e^t");

    show();
    return 0;
}

example_ylabel_6

 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 = transform(iota(1, 10), [](double x) { return pow(x, 2); });
    plot(x);
    ylabel("Population");
    auto ax = gca();
    ax->y_axis().label_font_size(12);
    ax->y_axis().label_weight("bold");
    ax->y_axis().label_color({0, 1, 0, 0});

    show();
    return 0;
}

example_ylabel_7

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

int main() {
    using namespace matplot;

    auto x1 = transform(iota(1, 10), [](double x) { return pow(x, 2); });
    auto x2 = transform(iota(1, 10), [](double x) { return pow(x, 3); });

    tiledlayout(2, 1);
    auto ax1 = nexttile();
    plot(x1);
    ylabel(ax1, "Population");

    auto ax2 = nexttile();
    plot(x2);

    show();
    return 0;
}

example_ylabel_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 = transform(iota(1, 10), [](double x) { return pow(x, 2); });
    plot(x);
    ylabel("Population");
    gca()->y_axis().label_color("red");

    show();
    return 0;
}