-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyaml_spec_example.cpp
More file actions
55 lines (48 loc) · 1.59 KB
/
yaml_spec_example.cpp
File metadata and controls
55 lines (48 loc) · 1.59 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
45
46
47
48
49
50
51
52
53
54
55
#include "example_common.hpp"
#include "gnuplotpp/plot.hpp"
#include "gnuplotpp/spec_yaml.hpp"
#include "gnuplotpp/templates.hpp"
#include <cmath>
#include <filesystem>
#include <fstream>
#include <string>
#include <vector>
int main(int argc, char** argv) {
using namespace gnuplotpp;
const std::filesystem::path out_dir =
example_common::parse_out_dir(argc, argv, "out/yaml_spec_example");
std::filesystem::create_directories(out_dir);
write_template_gallery_yaml(out_dir / "templates");
const auto yaml_path = out_dir / "figure.yaml";
{
std::ofstream os(yaml_path);
os << "figure:\n"
" title: YAML Driven Figure\n"
" caption: YAML config demo\n"
" preset: IEEE_DoubleColumn\n"
" palette: tab10\n"
" panel_labels: true\n"
" auto_layout: true\n"
" formats: [pdf, svg, png]\n"
"axes:\n"
" - title: Loaded from YAML\n"
" xlabel: t [s]\n"
" ylabel: y\n"
" grid: true\n"
" legend: true\n";
}
const auto spec = load_yaml_figure_spec(yaml_path);
Figure fig(spec.figure);
if (!spec.axes.empty()) {
fig.axes(0).set(spec.axes[0]);
}
std::vector<double> t(240), y1(240), y2(240);
for (int i = 0; i < 240; ++i) {
t[i] = 0.05 * static_cast<double>(i);
y1[i] = std::sin(0.7 * t[i]);
y2[i] = 0.8 * std::cos(0.6 * t[i] - 0.4);
}
fig.axes(0).add_series(SeriesSpec{.label = "series A"}, t, y1);
fig.axes(0).add_series(SeriesSpec{.label = "series B"}, t, y2);
return example_common::render_figure(fig, out_dir / "figures");
}