如何用c ++实时数据增加gnuplot的绘图频率?

Ove*_*ard 0 c++ iostream gnuplot real-time

我正在尝试使用C++实时显示传感器数据.传感器的输出高达1kHz,但gnuplot仅绘制大约10Hz的数据.

我正在使用gnuplot-iostream(http://stahlke.org/dan/gnuplot-iostream/)将数据从我的C++脚本传输到gnuplot,这很简单.但似乎绘图过程很慢,需要1/10秒来更新绘图.有没有办法增加这个频率?

编辑:这是一个简单代码的例子

#include <vector>
#include <utility>
#include <gnuplot-iostream/gnuplot-iostream.h>

typedef std::pair<double, double> Point;

int main() {
  std::vector<Point> data;

  double x = 0.0;
  double y = 0.0;
  double c = 0.0;

  Gnuplot gp;
  gp << "set terminal wxt size 800, 400\n";

  while (x < 10000) {
    x += 0.01;
    y = sin(x);
    c += 0.01;
    data.push_back(Point(x,y));
    //std::cout <<  x << std::endl;
    if (c > 0.1) {
      gp << "plot '-' with lines title 'sin(x)'\n";
      gp.send1d(data);
      c = 0.0;
    }
  }

  return 0;
}
Run Code Online (Sandbox Code Playgroud)

The*_*ist 6

如果传感器以1 kHz采样率输出数据,那绝对不意味着您应该使用该频率进行绘图.太疯狂了!如果您的眼睛无法看到该频率,那么以该频率绘制数据的重点是什么?

您应该像每0.1秒一样对要绘制的点进行分组,然后将它们与所有数据一起绘制.要明确:

  1. 收集一些数据,将其放入要绘制的数组中
  2. 绘制数组的数据
  3. 收集更多数据0.1秒(或0.2或0.5,或者每100个样本;这是你的电话)
  4. 将其添加到要绘制的数据数组中
  5. 可选:如果数组太大,则从前面修剪数据
  6. 绘制数据
  7. 回到3