1
0

lines3d.cpp 850 B

123456789101112131415161718192021222324252627282930
  1. #define _USE_MATH_DEFINES
  2. #include "../matplotlibcpp.h"
  3. #include <cmath>
  4. namespace plt = matplotlibcpp;
  5. int main()
  6. {
  7. std::vector<double> x, y, z;
  8. double theta, r;
  9. double z_inc = 4.0/99.0; double theta_inc = (8.0 * M_PI)/99.0;
  10. for (double i = 0; i < 100; i += 1) {
  11. theta = -4.0 * M_PI + theta_inc*i;
  12. z.push_back(-2.0 + z_inc*i);
  13. r = z[i]*z[i] + 1;
  14. x.push_back(r * sin(theta));
  15. y.push_back(r * cos(theta));
  16. }
  17. std::map<std::string, std::string> keywords;
  18. keywords.insert(std::pair<std::string, std::string>("label", "parametric curve") );
  19. plt::plot3(x, y, z, keywords);
  20. plt::xlabel("x label");
  21. plt::ylabel("y label");
  22. plt::set_zlabel("z label"); // set_zlabel rather than just zlabel, in accordance with the Axes3D method
  23. plt::legend();
  24. plt::show();
  25. }