| 2 | #include <matplot/matplot.h> |
| 3 | |
| 4 | int main() { |
| 5 | using namespace matplot; |
| 6 | |
| 7 | // Create figure with backend |
| 8 | auto f = figure<backend::opengl>(true); |
| 9 | auto ax = f->current_axes(); |
| 10 | ax->xlim({0., 2. * pi}); |
| 11 | ax->ylim({-1.5, 1.5}); |
| 12 | ax->yticks(iota(-1.5, 0.5, +1.5)); |
| 13 | ax->xticks(iota(0., 1., 2. * pi)); |
| 14 | |
| 15 | // Another figure |
| 16 | auto f2 = figure<backend::opengl>(true); |
| 17 | auto ax2 = f2->add_subplot(2, 1, 0); |
| 18 | auto ax3 = f2->add_subplot(2, 1, 1); |
| 19 | |
| 20 | // Start rendering |
| 21 | while (!f->should_close() && !f2->should_close()) { |
| 22 | // Create plots |
| 23 | double seconds = backend::opengl::get_time(); |
| 24 | std::vector<double> x = linspace(0., 2. * pi); |
| 25 | std::vector<double> y = |
| 26 | transform(x, [&](auto x) { return sin(x + seconds); }); |
| 27 | ax->hold(off); |
| 28 | ax->plot(x, y, "-o"); |
| 29 | ax->hold(on); |
| 30 | const vector_1d minus_y = transform(y, [](auto y) { return -y; }); |
| 31 | ax->plot(x, minus_y, "--xr"); |
| 32 | ax->plot(x, transform(x, [](auto x) { return x / pi - 1.; }), "-:gs"); |
| 33 | ax->plot({1.0, 0.7, 0.4, 0.0, -0.4, -0.7, -1}, "k"); |
| 34 | |
| 35 | // Only one line in figure 2 |
| 36 | ax2->plot(x, y, "-o"); |
| 37 | ax3->plot(x, minus_y, "--xr"); |
| 38 | |
| 39 | // Draw the figures |
| 40 | f->draw(); |
| 41 | f2->draw(); |
| 42 | } |
| 43 | |
| 44 | return 0; |
| 45 | } |
nothing calls this directly
no test coverage detected