【发布时间】:2022-06-30 14:56:25
【问题描述】:
我正在尝试使用 matplotlib 库从向量向量中绘制一些值,但这对我来说是不可能的。我认为我的问题是因为我如何声明此向量,但我找不到另一种处理此类数据的方法。
我需要使用 6x1500 浮点数组,然后绘制所有行。请问有人可以帮我吗?这是我的代码,它是我的主脚本的一个简单示例。
#include <iostream>
#include "matplotlibcpp.h"
#include <vector>
#include <random>
#include <iostream>
#include <fstream>
#include <cstdio>
namespace plt = matplotlibcpp;
using namespace std;
int main() {
std::vector<std::array<float, 1500>> y(6);
float r = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
for (int i = 0; i <1500; i++) {
for (int j = 0; j < 6; j++) {
y[j][i] = r;
cout << "test[" << i << "][" << j << "] = " << y[j][i] << endl;
}
}
plt::figure();
plt::plot("log(x)", y.at(0), "b--");
plt::xlabel("time (s)");
plt::ylabel("Error (deg)");
plt::legend();
/*
plt::figure();
plt::named_plot("log(x)", y, "b--");
plt::xlabel("time (s)");
plt::ylabel("position (deg)");
plt::legend();
*/
//plt::title("Trajectory");
//plt::xlabel("time (s)");
//plt::ylabel("position (deg)");
//plt::legend();
// Set x-axis to interval [0,1000000]
//plt::xlim(0, n * n);
//plt::grid();
plt::show();
}
提前致谢!
【问题讨论】:
-
但对我来说不可能是什么意思?如果有编译时错误,请将其包含在 Q 中。如果编译后的程序没有输出预期的结果,请包含详细信息。
标签: c++ arrays matplotlib plot stdvector