subplot2grid.cpp 919 B

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