nonblock.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #define _USE_MATH_DEFINES
  2. #include <cmath>
  3. #include "../matplotlibcpp.h"
  4. namespace plt = matplotlibcpp;
  5. using namespace matplotlibcpp;
  6. using namespace std;
  7. int main()
  8. {
  9. // Prepare data.
  10. int n = 5000;
  11. std::vector<double> x(n), y(n), z(n), w(n,2);
  12. for(int i=0; i<n; ++i) {
  13. x.at(i) = i*i;
  14. y.at(i) = sin(2*M_PI*i/360.0);
  15. z.at(i) = log(i);
  16. }
  17. // Plot line from given x and y data. Color is selected automatically.
  18. plt::subplot(2,2,1);
  19. plt::plot(x, y);
  20. // Plot a red dashed line from given x and y data.
  21. plt::subplot(2,2,2);
  22. plt::plot(x, w,"r--");
  23. // Plot a line whose name will show up as "log(x)" in the legend.
  24. plt::subplot(2,2,3);
  25. plt::named_plot("log(x)", x, z);
  26. // Set x-axis to interval [0,1000000]
  27. plt::xlim(0, 1000*1000);
  28. // Add graph title
  29. plt::title("Sample figure");
  30. // Enable legend.
  31. plt::legend();
  32. plt::show(false);
  33. cout << "matplotlibcpp::show() is working in an non-blocking mode" << endl;
  34. getchar();
  35. }