blob: f590e51cae7fef33e4e7e01d421e2ee189447aea [file] [log] [blame]
Austin Schuhab802d52020-07-03 18:11:11 -07001#define _USE_MATH_DEFINES
2#include <cmath>
3#include "../matplotlibcpp.h"
4
5using namespace std;
6namespace plt = matplotlibcpp;
7
8int main()
9{
10 // Prepare data
11 int n = 500;
12 std::vector<double> x(n), u(n), v(n), w(n);
13 for(int i=0; i<n; ++i) {
14 x.at(i) = i;
15 u.at(i) = sin(2*M_PI*i/500.0);
16 v.at(i) = 100.0 / i;
17 w.at(i) = sin(2*M_PI*i/1000.0);
18 }
19
20 // Set the "super title"
21 plt::suptitle("My plot");
22
23 const long nrows=3, ncols=3;
24 long row = 2, col = 2;
25
26 plt::subplot2grid(nrows, ncols, row, col);
27 plt::plot(x, w, "g-");
28
29 long spanr = 1, spanc = 2;
30 col = 0;
31 plt::subplot2grid(nrows, ncols, row, col, spanr, spanc);
32 plt::plot(x, v, "r-");
33
34 spanr = 2, spanc = 3;
35 row = 0, col = 0;
36 plt::subplot2grid(nrows, ncols, row, col, spanr, spanc);
37 plt::plot(x, u, "b-");
38 // Add some text to the plot
39 plt::text(100., -0.5, "Hello!");
40
41
42 // Show plots
43 plt::show();
44}