|
13 | 13 | namespace py = pybind11; |
14 | 14 | using namespace py::literals; |
15 | 15 | using namespace std; |
| 16 | +using namespace matplotlibcpp17; |
16 | 17 | using namespace matplotlibcpp17::util; |
17 | 18 |
|
18 | 19 | int main() { |
19 | 20 | py::scoped_interpreter guard{}; |
20 | 21 | auto plt = matplotlibcpp17::pyplot::import(); |
| 22 | + auto [fig, ax] = plt.subplots(); |
| 23 | + |
| 24 | + const int N = 3; |
| 25 | + vector<double> x = {0.7003673, 0.74275081, 0.70928001}, |
| 26 | + y = {0.56674552, 0.97778533, 0.70633485}, |
| 27 | + radii = {0.02479158, 0.01578834, 0.06976985}; |
| 28 | + py::list patches; // instead of patches = [] |
| 29 | + for (int i = 0; i < N; ++i) { |
| 30 | + const double x1 = x[i], y1 = y[i], r = radii[i]; |
| 31 | + auto circle = patches::Circle(args_(py::make_tuple(x1, y1), r)); |
| 32 | + patches.append(circle.unwrap()); |
| 33 | + } |
| 34 | + x = {0.71995667, 0.25774443, 0.34154678}; |
| 35 | + y = {0.96876117, 0.6945071, 0.46638326}; |
| 36 | + radii = {0.07028127, 0.05117859, 0.09287414}; |
| 37 | + vector<double> theta1 = {266.3169476, 224.07805212, 234.5563688}, |
| 38 | + theta2 = {142.85074015, 195.56618216, 287.96383014}; |
| 39 | + for (int i = 0; i < N; ++i) { |
| 40 | + const double x1 = x[i], y1 = y[i], r = radii[i], th1 = theta1[i], |
| 41 | + th2 = theta2[i]; |
| 42 | + auto wedge = patches::Wedge(args_(py::make_tuple(x1, y1), r, th1, th2)); |
| 43 | + patches.append(wedge.unwrap()); |
| 44 | + } |
| 45 | + patches.append( |
| 46 | + patches::Wedge(args_(py::make_tuple(0.3, 0.7), 0.1, 0, 360)).unwrap()); |
| 47 | + patches.append(patches::Wedge(args_(py::make_tuple(0.7, 0.8), 0.2, 0, 360), |
| 48 | + kwargs_("width"_a = 0.05)) |
| 49 | + .unwrap()); |
| 50 | + patches.append( |
| 51 | + patches::Wedge(args_(py::make_tuple(0.8, 0.3), 0.2, 0, 45)).unwrap()); |
| 52 | + patches.append(patches::Wedge(args_(py::make_tuple(0.8, 0.3), 0.2, 45, 90), |
| 53 | + kwargs_("width"_a = 0.10)) |
| 54 | + .unwrap()); |
| 55 | + // NOTE: Polygon take numpy array as argument, so skip it |
| 56 | + vector<double> colors_ = {90.63036451, 16.10182093, 74.36211347, 63.29741618, |
| 57 | + 32.41800177, 92.23765324, 23.72264387, 82.39455709, |
| 58 | + 75.06071403, 11.37844527}; |
| 59 | + py::list colors = py::cast(colors_); |
| 60 | + auto p = |
| 61 | + collections::PathCollection(args_(patches), kwargs_("alpha"_a = 0.4)); |
| 62 | + p.set_array(colors); |
| 63 | + ax.add_collection(p.unwrap()); // erroneous |
| 64 | + // fig.colorbar(p.unwrap(), "ax"_a = ax.unwrap()); |
| 65 | + plt.show(); |
| 66 | + return 0; |
21 | 67 | } |
0 commit comments