Skip to content

Pie Chart

1
pie(x);

example_pie_1

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

int main() {
    using namespace matplot;

    std::vector<double> x = {1, 3, 0.5, 2.5, 2};
    pie(x);

    show();
    return 0;
}

More examples

example_pie_2

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

int main() {
    using namespace matplot;

    std::vector<double> x = {1, 3, 0.5, 2.5, 2};
    std::vector<double> explode = {0, 1, 0, 1, 0};
    pie(x, explode);

    show();
    return 0;
}

example_pie_3

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

int main() {
    using namespace matplot;

    std::vector<double> x = iota(1, 3);
    std::vector<std::string> labels = {"Taxes", "Expenses", "Profit"};
    pie(x, labels);

    show();
    return 0;
}

example_pie_4

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

int main() {
    using namespace matplot;

    std::vector<double> x = {0.19, 0.22, 0.41};
    pie(x);

    show();
    return 0;
}

example_pie_5

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

int main() {
    using namespace matplot;

    std::vector<double> y2010 = {50, 0, 100, 95};
    std::vector<double> y2011 = {65, 22, 97, 120};
    std::vector<std::string> labels = {"Investments", "Cash", "Operations",
                                       "Sales"};

    tiledlayout(2, 1);
    auto ax1 = nexttile();
    pie(ax1, y2010);
    title("2010");

    auto ax2 = nexttile();
    pie(ax2, y2011);
    title("2011");

    show();
    return 0;
}

example_pie_6

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

int main() {
    using namespace matplot;

    std::vector<double> x = {17, 33, 33, 17};
    std::vector<double> explode = {0, 1, 1, 0};
    std::vector<std::string> labels = {"East (17%)", "North (33%)",
                                       "South (33%)", "West (17%)"};

    pie(x, explode, labels);

    show();
    return 0;
}