fill_inbetween.cpp 678 B

12345678910111213141516171819202122232425262728
  1. #define _USE_MATH_DEFINES
  2. #include "../matplotlibcpp.h"
  3. #include <cmath>
  4. #include <iostream>
  5. using namespace std;
  6. namespace plt = matplotlibcpp;
  7. int main() {
  8. // Prepare data.
  9. int n = 5000;
  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 * i;
  13. y.at(i) = sin(2 * M_PI * i / 360.0);
  14. z.at(i) = log(i);
  15. }
  16. // Prepare keywords to pass to PolyCollection. See
  17. // https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.fill_between.html
  18. std::map<string, string> keywords;
  19. keywords["alpha"] = "0.4";
  20. keywords["color"] = "grey";
  21. keywords["hatch"] = "-";
  22. plt::fill_between(x, y, z, keywords);
  23. plt::show();
  24. }