Skip to content

Parallel Coordinates

1
parallelplot(X);

example_parallelplot_1

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

int main() {
    using namespace matplot;

    std::vector<std::vector<double>> X(3);
    X[0] = concat(rand(50, 78, 100), rand(50, 65, 91));
    X[1] = concat(std::vector<double>(50, 1), std::vector<double>(50, 0));
    X[2] = concat(rand(50, 122, 140), rand(50, 105, 131));

    auto p = parallelplot(X);

    gca()->x_axis().tick_values({1, 2, 3});
    gca()->x_axis().ticklabels({"f_1", "f_2", "f_3"});

    p->axis()[1].tick_values({0, 1});
    p->axis()[1].ticklabels({"false", "true"});

    show();
    return 0;
}

More examples

example_parallelplot_2

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

int main() {
    using namespace matplot;

    std::vector<std::vector<double>> X(4);
    X[0] = concat(rand(50, 78, 200), rand(50, 65, 91));
    X[1] = concat(std::vector<double>(50, 1), std::vector<double>(50, 0));
    X[2] = concat(rand(50, 122, 140), rand(50, 105, 131));
    X[3] =
        concat(concat(std::vector<double>(25, 3), std::vector<double>(50, 1)),
               std::vector<double>(25, 2));

    auto p = parallelplot(X, X[3]);

    gca()->x_axis().tick_values({1, 2, 3, 4});
    gca()->x_axis().ticklabels({"f_1", "f_2", "f_3", "f_4"});

    p->axis()[1].tick_values({0, 1});
    p->axis()[1].ticklabels({"false", "true"});

    p->axis()[3].tick_values({1, 2, 3});
    p->axis()[3].ticklabels({"low", "medium", "high"});

    show();
    return 0;
}

example_parallelplot_3

 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;

    std::vector<std::vector<double>> X(4);
    X[0] = randn(100, 50, 200);
    X[1] = transform(X[0], [](double x) { return x + rand(-30, +30); });
    X[2] = transform(X[0], [](double x) { return x > 50 ? +1. : -1.; });
    X[3].resize(X[0].size());
    std::generate(X[3].begin(), X[3].end(),
                  []() { return cos(rand(-30, +30)); });

    auto colors = X[2];
    parallelplot(X, colors);

    show();
    return 0;
}

The function parallelplot creates a plot with Parallel Coordinates. In this type of plot, a parallel lines object stores an arbitrary set of axis objects to represent multi-dimensional data.