qq_42585801 2022-10-13 20:14 采纳率: 33.3%
浏览 47

matplotlib c++ 3维图像更新问题

问题遇到的现象和发生背景

我在使用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);
    }
}


运行结果及报错内容

img

我想要达到的结果

在这个坐标轴中更新画面

  • 写回答

1条回答 默认 最新

  • Dana_ranmo 2022-10-14 10:26
    关注
    
    #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;
    
        plt::figure(1);//新建画板1
    
        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::cla();//清楚当前axes内容
    
            plt::plot3(x, y, z, {}, 1);//在画板1上画
    
            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);
    
        }
    
    }
    
    评论

报告相同问题?

问题事件

  • 创建了问题 10月13日

悬赏问题

  • ¥15 模电中二极管,三极管和电容的应用
  • ¥15 关于模型导入UNITY的.FBX: Check external application preferences.警告。
  • ¥15 气象网格数据与卫星轨道数据如何匹配
  • ¥100 java ee ssm项目 悬赏,感兴趣直接联系我
  • ¥15 微软账户问题不小心注销了好像
  • ¥15 x264库中预测模式字IPM、运动向量差MVD、量化后的DCT系数的位置
  • ¥15 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused
  • ¥20 关于web前端如何播放二次加密m3u8视频的问题
  • ¥15 使用百度地图api 位置函数报错?
  • ¥15 metamask如何添加TRON自定义网络