问题遇到的现象和发生背景
我在使用matplotlib c++版本过程中,想实时绘制3维度坐标数据;实际运行中发现无法只更新画布,且实际效果创建了很多张图,我应该怎么修改代码呢
用代码块功能插入代码,请勿粘贴截图
#define _USE_MATH_DEFINES
#include "matplotlibcpp.h"
#include <cmath>
namespace plt = matplotlibcpp;
int main()
{
std::vector<double> x, y, z;
double theta, r;
double z_inc = 4.0 / 99.0; double theta_inc = (8.0 * M_PI) / 99.0;
for (double i = 0; i < 100; i += 1) {
theta = -4.0 * M_PI + theta_inc * i;
z.push_back(-2.0 + z_inc * i);
r = z[i] * z[i] + 1;
x.push_back(r * sin(theta));
y.push_back(r * cos(theta));
std::map<std::string, std::string> keywords;
keywords.insert(std::pair<std::string, std::string>("label", "parametric curve"));
plt::plot3(x, y, z);
plt::xlabel("x label");
plt::ylabel("y label");
plt::set_zlabel("z label"); // set_zlabel rather than just zlabel, in accordance with the Axes3D method
plt::legend();
plt::pause(0.01);
}
}
运行结果及报错内容
我想要达到的结果
在这个坐标轴中更新画面