forked from soblin/matplotlibcpp17
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlines3d.cpp
More file actions
37 lines (32 loc) · 1.15 KB
/
Copy pathlines3d.cpp
File metadata and controls
37 lines (32 loc) · 1.15 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
// example from https://matplotlib.org/stable/gallery/mplot3d/lines3d.html
#include <matplotlibcpp17/pyplot.h>
#include <matplotlibcpp17/mplot3d.h>
#include <xtensor/xbuilder.hpp>
#include <xtensor/xmath.hpp>
#include <vector>
using namespace std;
using namespace matplotlibcpp17;
int main() {
py::scoped_interpreter guard{};
auto plt = matplotlibcpp17::pyplot::import();
// this is required for "projection = 3d"
matplotlibcpp17::mplot3d::import();
auto fig = plt.figure();
auto ax = fig.add_subplot(Args(), Kwargs("projection"_a = "3d"));
const auto theta_ = xt::linspace(-4 * M_PI, 4 * M_PI, 100);
const auto z_ = xt::linspace(-2.0, 2.0, 100);
const auto r_ = 1.0 + xt::pow(z_, 2);
const auto x_ = r_ * xt::sin(theta_);
const auto y_ = r_ * xt::cos(theta_);
const vector<double> z(z_.begin(), z_.end());
const vector<double> r(r_.begin(), r_.end());
const vector<double> theta(theta_.begin(), theta_.end());
const vector<double> x(x_.begin(), x_.end()), y(y_.begin(), y_.end());
ax.plot(Args(x, y, z), Kwargs("label"_a = "parametric curve"));
ax.legend();
#if USE_GUI
plt.show();
#else
plt.savefig(Args("lines3d.png"));
#endif
}