forked from soblin/matplotlibcpp17
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_lib.cpp
More file actions
38 lines (31 loc) · 1016 Bytes
/
Copy pathtest_lib.cpp
File metadata and controls
38 lines (31 loc) · 1016 Bytes
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
// example from
// https://matplotlib.org/stable/gallery/lines_bars_and_markers/simple_plot.html
#include <matplotlibcpp17/pyplot.h>
#include <algorithm>
#include <vector>
template <typename T> std::vector<T> arange(T start, T end, T h) {
int N = static_cast<int>((end - start) / h);
std::vector<T> xs(N);
T val = start;
while (val <= end) {
xs.push_back(val);
val += h;
}
return xs;
}
using namespace std;
using namespace matplotlibcpp17;
void func() {
auto plt = matplotlibcpp17::pyplot::import();
auto t = arange(0.0, 2.0, 0.01);
decltype(t) s;
transform(t.begin(), t.end(), back_inserter(s),
[](double x) { return 1.0 + sin(2 * M_PI * x); });
auto [fig, ax] = plt.subplots();
ax.plot(Args(t, s), Kwargs("color"_a = "blue", "linewidth"_a = 1.0));
ax.set(Args(), Kwargs("xlabel"_a = "time (s)", "ylabel"_a = "voltage (mV)",
"title"_a = "About as simple as it gets, folks"));
ax.grid();
fig.savefig(Args("test.png"));
plt.show();
}