Skip to content

Loglog Plot

1
loglog(x,y);

example_loglog_1

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

int main() {
    using namespace matplot;

    std::vector<double> x = logspace(-1, 2);
    std::vector<double> y = transform(x, [](auto x) { return pow(2, x); });
    loglog(x, y);

    show();
    return 0;
}

More examples

example_loglog_2

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

int main() {
    using namespace matplot;

    std::vector<double> x = logspace(-1, 2);
    std::vector<double> y1 = transform(x, [](auto x) { return pow(10, x); });
    std::vector<double> y2 =
        transform(x, [](auto x) { return 1 / pow(10, x); });
    loglog(x, y1, x, y2);

    show();
    return 0;
}

example_loglog_3

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

int main() {
    using namespace matplot;

    std::vector<double> x = logspace(-1, 2, 10000);
    std::vector<double> y = transform(x, [](auto x) { return 5 + 3 * sin(x); });
    loglog(x, y);
    yticks({3, 4, 5, 6, 7});
    xlabel("x");
    ylabel("5+3 sin(x)");

    show();
    return 0;
}

example_loglog_4

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

int main() {
    using namespace matplot;

    std::vector<double> x = logspace(-1, 2, 20);
    std::vector<double> y =
        transform(x, [](double x) { return std::pow(10., x); });
    loglog(x, y, "s")->marker_face_color({0.f, 0.447f, 0.741f});
    xlabel("x");
    ylabel("10^x");

    show();
    return 0;
}

example_loglog_5

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

int main() {
    using namespace matplot;

    std::vector<double> x = logspace(-1, 2, 10000);
    std::vector<double> y1 =
        transform(x, [](auto x) { return 5 + 3 * sin(x / 4); });
    std::vector<double> y2 =
        transform(x, [](auto x) { return 5 - 3 * sin(x / 4); });

    loglog(x, y1, x, y2, "--");

    ::matplot::legend({"Signal 1", "Signal 2"})
        ->location(legend::general_alignment::topleft);

    axis({0.1, 100, 2, 8});

    show();
    return 0;
}

example_loglog_6

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

int main() {
    using namespace matplot;

    std::vector<double> y = {0.001, 0.01, 0.1, 1, 10, 100};
    loglog(y);

    show();
    return 0;
}

example_loglog_7

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

int main() {
    using namespace matplot;

    std::vector<std::vector<double>> Y = {
        {0.0010, 0.0100, 0.1000, 1.0000, 10.0000},
        {0.0100, 0.1000, 1.0000, 10.0000, 100.0000},
        {0.1000, 1.0000, 10.0000, 100.0000, 1000.0000}};
    loglog(Y);

    show();
    return 0;
}

example_loglog_8

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

int main() {
    using namespace matplot;

    tiledlayout(2, 1);
    auto ax1 = nexttile();
    std::vector<double> x = logspace(-1, 2);
    std::vector<double> y1 = transform(x, [](auto x) { return pow(10, x); });
    loglog(ax1, x, y1);

    auto ax2 = nexttile();
    std::vector<double> y2 =
        transform(x, [](auto x) { return 1. / pow(10, x); });
    loglog(ax2, x, y2);

    show();
    return 0;
}

example_loglog_9

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

int main() {
    using namespace matplot;

    std::vector<double> x = logspace(-1, 2);
    std::vector<double> y1 = transform(x, [](auto x) { return pow(10, x); });
    std::vector<double> y2 =
        transform(x, [](auto x) { return 1. / pow(10, x); });
    auto lg = loglog(x, y1, x, y2);
    lg[0]->line_width(2);
    lg[1]->color({0.4f, 0.f, 1.f});

    show();
    return 0;
}