I'm trying to visualize sensor data in real time using C++. The sensor has an output of up to 1kHz, but gnuplot is only plotting the data at about 10Hz.
I'm using gnuplot-iostream (http://stahlke.org/dan/gnuplot-iostream/) to pipe the data to gnuplot from my C++ script, which is simple and easy. But it seems like the plotting process is slow, and takes 1/10th of a second to update the plot. Is there any way of increasing this frequency?
EDIT: Here's an example of a simple code
#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;
}
答案 0 :(得分:6)
如果传感器以1 kHz的采样率输出数据,那绝对不意味着您应该以该频率进行绘制。太疯狂了!如果您的眼睛看不到以该频率绘制数据,那么绘制数据的重点是什么?
您应该像每隔0.1秒一样对要绘制的点进行分组,然后将它们与所有数据一起绘制。要清楚: