Skip to content

Polar Histogram

1
polarhistogram(theta, 6);

example_polarhistogram_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 = {0.1, 1.1, 5.4, 3.4, 2.3, 4.5, 3.2,
                                 3.4, 5.6, 2.3, 2.1, 3.5, 0.6, 6.1};
    polarhistogram(theta, 6);

    show();
    return 0;
}

More examples

example_polarhistogram_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;

    auto r1 = rand(100000, 0, 1);
    auto r2 = rand(100000, 0, 1);
    std::vector<double> theta = transform(
        r1, r2, [](double x, double y) { return atan2(x - .5, 2 * (y - .5)); });
    polarhistogram(theta, 25);

    show();
    return 0;
}

example_polarhistogram_3

 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;

    auto r1 = rand(100000, 0, 1);
    auto r2 = rand(100000, 0, 1);
    std::vector<double> theta = transform(
        r1, r2, [](double x, double y) { return atan2(x - .5, 2 * (y - .5)); });
    auto h = polarhistogram(theta, 25);
    h->face_color("red");
    h->face_alpha(1.f - 0.3f);

    show();
    return 0;
}

example_polarhistogram_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;

    auto r1 = rand(100000, 0, 1);
    auto r2 = rand(100000, 0, 1);
    std::vector<double> theta = transform(
        r1, r2, [](double x, double y) { return atan2(x - .5, 2 * (y - .5)); });
    auto h = polarhistogram(theta, 25);
    h->stairs_only(true);

    show();
    return 0;
}

example_polarhistogram_5

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

int main() {
    using namespace matplot;

    std::vector<double> y = randp(100, 1.0, 0.5);
    polarhistogram(y, 25);

    show();
    return 0;
}

The function polarhistogram distributes the data into the number of bins provided as its second parameter.