Skip to content

Color Bar

1
colorbar();

example_colorbar_1

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

int main() {
    using namespace matplot;

    auto [x, y, z] = peaks();
    surf(x, y, z);
    colorbar();

    show();
    return 0;
}

More examples

example_colorbar_2

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

int main() {
    using namespace matplot;

    auto [x, y, z] = peaks();
    contourf(x, y, z, 20);
    gca()->cb_position({0.f, 0.f, 1.f, 0.06f});

    show();
    return 0;
}

example_colorbar_3

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

int main() {
    using namespace matplot;

    auto [x, y, z] = peaks();
    surf(x, y, z);
    colorbar().reverse(true);

    show();
    return 0;
}

example_colorbar_4

 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 [x, y, z] = peaks();
    tiledlayout(2, 1);

    nexttile();
    surf(x, y, z);
    colorbar();

    nexttile();
    mesh(x, y, z);
    colorbar();

    show();
    return 0;
}

example_colorbar_5

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

int main() {
    using namespace matplot;

    auto [x, y, z] = peaks();
    contourf(x, y, z);
    colorbar()
        .limits({-6, 8})
        .tick_values({-5, -2, 1, 4, 7})
        .ticklabels({"Cold", "Cool", "Neutral", "Warm", "Hot"});

    show();
    return 0;
}

example_colorbar_6

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

int main() {
    using namespace matplot;

    std::vector<std::vector<double>> map = {{0, 0, 0.3}, {0, 0, 0.4},
                                            {0, 0, 0.5}, {0, 0, 0.6},
                                            {0, 0, 0.8}, {0, 0, 1}};
    auto [x, y, z] = peaks();
    surf(x, y, z);
    colorbar().label("Elevation (ft in 1000s)");

    show();
    return 0;
}

example_colorbar_7

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

int main() {
    using namespace matplot;

    auto [x, y, z] = peaks();
    surf(x, y, z);
    colorbar(on);
    colorbar(off);

    show();
    return 0;
}