lines3d.cpp 825 B

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