subplot.cpp 587 B

12345678910111213141516171819202122232425262728293031
  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), y(n), z(n), w(n,2);
  11. for(int i=0; i<n; ++i) {
  12. x.at(i) = i;
  13. y.at(i) = sin(2*M_PI*i/360.0);
  14. z.at(i) = 100.0 / i;
  15. }
  16. // Set the "super title"
  17. plt::suptitle("My plot");
  18. plt::subplot(1, 2, 1);
  19. plt::plot(x, y, "r-");
  20. plt::subplot(1, 2, 2);
  21. plt::plot(x, z, "k-");
  22. // Add some text to the plot
  23. plt::text(100, 90, "Hello!");
  24. // Show plots
  25. plt::show();
  26. }