forked from soblin/matplotlibcpp17
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrorbar3d.cpp
More file actions
44 lines (35 loc) · 1.33 KB
/
Copy patherrorbar3d.cpp
File metadata and controls
44 lines (35 loc) · 1.33 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// example from https://matplotlib.org/stable/gallery/mplot3d/errorbar3d.html
#include <matplotlibcpp17/pyplot.h>
#include <xtensor/xbuilder.hpp>
#include <xtensor/xmath.hpp>
#include <vector>
#include <algorithm>
using namespace std;
using namespace matplotlibcpp17;
int main() {
py::scoped_interpreter guard{};
auto plt = pyplot::import();
auto ax = plt.figure().add_subplot(Args(), Kwargs("projection"_a = "3d"));
auto t_ = xt::arange(0.0, 2 * M_PI + 0.1, 0.01);
auto x_ = xt::sin(1.0 * t_);
auto y_ = xt::cos(3.0 * t_);
auto z_ = xt::sin(5.0 * t_);
vector<double> t(t_.begin(), t_.end()), x(x_.begin(), x_.end()),
y(y_.begin(), y_.end()), z(z_.begin(), z_.end());
const int estep = 15;
vector<int> i(t_.shape()[0]), zuplims, zlolims;
std::iota(i.begin(), i.end(), t_.shape()[0]);
std::transform(i.begin(), i.end(), std::back_inserter(zuplims), [](int i) {
return (i % 15 == 0) and ((i / estep) % 3 == 0);
});
std::transform(i.begin(), i.end(), std::back_inserter(zlolims), [](int i) {
return (i % 15 == 0) and ((i / estep) % 3 == 2);
});
ax.errorbar(Args(x, y, z, 0.2),
Kwargs("zuplims"_a = zuplims, "zlolims"_a = zlolims,
"errorevery"_a = estep));
ax.set_xlabel(Args("X label"));
ax.set_ylabel(Args("Y label"));
ax.set_zlabel(Args("Z label"));
plt.show();
}