Skip to content

Polar Scatter Plot

1
polarscatter(theta, rho);

example_polarscatter_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> theta = iota(pi / 4, pi / 4, 2 * pi);
    std::vector<double> rho = {19, 6, 12, 18, 16, 11, 15, 15};
    polarscatter(theta, rho);

    show();
    return 0;
}

More examples

example_polarscatter_2

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

int main() {
    using namespace matplot;

    std::vector<double> theta = linspace(0, 2 * pi, 20);
    std::vector<double> rho = rand(20, 0, 1);
    double size = 10;
    polarscatter(theta, rho, size, "filled");

    show();
    return 0;
}

example_polarscatter_3

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

int main() {
    using namespace matplot;

    std::vector<double> theta = iota(pi / 4, pi / 4, 2 * pi);
    std::vector<double> rho = {19, 6, 12, 18, 16, 11, 15, 15};
    std::vector<double> sizes = {
        6 * 2, 15 * 2, 20 * 2, 3 * 2, 15 * 2, 3 * 2, 6 * 2, 40 * 2,
    };
    std::vector<double> colors = {
        1, 2, 2, 2, 1, 1, 2, 1,
    };
    auto s = polarscatter(theta, rho, sizes, colors, "filled");

    show();
    return 0;
}

example_polarscatter_4

 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> theta = linspace(0, 360, 50);
    std::vector<double> rho =
        transform(theta, [](double t) { return 0.005 * t / 10.; });
    std::vector<double> th_radians = deg2rad(theta);
    auto s = polarscatter(th_radians, rho);

    show();
    return 0;
}

example_polarscatter_5

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

int main() {
    using namespace matplot;

    std::vector<double> theta = iota(pi / 6, pi / 6, 2 * pi);
    std::vector<double> rho1 = rand(12, 0, 1);
    polarscatter(theta, rho1, "filled");

    hold(on);
    std::vector<double> rho2 = rand(12, 0, 1);
    polarscatter(theta, rho2, "filled");
    hold(off);

    auto l = ::matplot::legend({"Series A", "Series B"});
    l->location(legend::general_alignment::topright);

    show();
    return 0;
}

example_polarscatter_6

 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> theta = iota(pi / 6, pi / 6, 2 * pi);
    std::vector<double> rho1 = rand(12, 0, 1);
    auto ps = polarscatter(theta, rho1, "filled");
    ps->marker("square");
    ps->marker_size(20);
    ps->marker_color({0.5, 1, 0, 0});

    show();
    return 0;
}