Skip to content

Image Matrix

1
image(C);

example_image_1

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

int main() {
    using namespace matplot;
    std::vector<std::vector<double>> C = {
        {0, 2, 4, 6}, {8, 10, 12, 14}, {16, 18, 20, 22}};
    image(C);
    colorbar();

    show();
    return 0;
}

More examples

example_image_2

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

int main() {
    using namespace matplot;
    std::vector<std::vector<double>> C = {
        {0, 2, 4, 6}, {8, 10, 12, 14}, {16, 18, 20, 22}};
    image(C, true);
    colorbar();

    show();
    return 0;
}

example_image_3

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

int main() {
    using namespace matplot;
    std::vector<std::vector<double>> C = {
        {0, 2, 4, 6}, {8, 10, 12, 14}, {16, 18, 20, 22}};
    image(5, 8, 3, 6, C);

    show();
    return 0;
}

example_image_4

 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;
    std::tuple<vector_2d, vector_2d, vector_2d> C;
    auto &[r, g, b] = C;
    r = transform(vector_2d{{.1, .2, .3}, {.4, .5, .6}, {.7, .8, .9}},
                  [](double x) { return x * 255; });
    g = zeros(3, 3);
    b = zeros(3, 3);

    image(C);

    show();
    return 0;
}

example_image_5

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

int main() {
    using namespace matplot;
    plot(iota(1, 3));
    hold(on);
    vector_2d C = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
    auto im = image(C);
    im->alpha(0.5);
    gca()->y_axis().reverse(false);

    show();
    return 0;
}