MCPcopy Create free account
hub / github.com/alandefreitas/matplotplusplus / main

Function main

test/backends/ogl_main.cpp:4–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#include <matplot/matplot.h>
3
4int 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}

Callers

nothing calls this directly

Calls 13

iotaFunction · 0.85
linspaceFunction · 0.85
transformFunction · 0.85
current_axesMethod · 0.80
xlimMethod · 0.80
ylimMethod · 0.80
yticksMethod · 0.80
xticksMethod · 0.80
add_subplotMethod · 0.80
holdMethod · 0.80
plotMethod · 0.80
should_closeMethod · 0.45

Tested by

no test coverage detected