从txt文件实时绘制Gnuplot C ++ [英] Gnuplot C++ plotting in real time from txt files

查看:62
本文介绍了从txt文件实时绘制Gnuplot C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在通过c ++中的管道从文件中绘制数据.我编写了一个函数,可以读取文本文件,处理信息,在文本文件中绘制数据并根据需要绘制标签和箭头.

Hi I am currently plotting data from a file through a pipe in c++. I have written a function that reads in the text file, processes the information, plots the data in the text file and plots labels and arrows as needed.

现在,我需要一种在循环中平滑绘制的方法,以便在每次迭代时读取和绘制一个不同的文本文件,而不会导致Gnuplot窗口闪烁.

Now I need a way to plot smoothly in a loop, so that a different text file is read and plotted every iteration without the Gnuplot window flickering.

例如:

for (unsigned int i = 0; i< 10; i++){
    Processing_Plotting(i, gp);
}

这是我在主程序中拥有的代码,它将绘制由"i"指示的文本文件.例如:laserData1,laserData2等.

This is the code i have in the main program which will plot the text file indicated by 'i'. eg: laserData1, laserData2 etc..

当前,图形闪烁,由于调用速度太快而无法读取.我一直在寻找一种使用Gnuplot实时绘制数据的方法,但是运气不佳,任何帮助,将不胜感激.谢谢

Currently the plot flickers and is unreadable due to the speed that it is called. I have looked for a way to plot data in real time with Gnuplot but haven't had much luck, any help would be appreciated. Thanks

我正在画的东西的图片: http://imgur.com/3eTpMaB

A picture of the sort of thing I am plotting: http://imgur.com/3eTpMaB

推荐答案

gnuplot-iostream 库.它不会闪烁,至少不会在我的计算机(Linux)上闪烁.免责声明:我是该库的作者,所以这是一个无耻的插件.

There is an example of an animation that comes with the gnuplot-iostream library. It doesn't flicker, at least not on my machine (Linux). Disclaimer: I'm the author of that library, so that is a shameless plug.

您的代码片段未显示您实际如何与gnuplot交互,但是您必须确保执行三件事:1)在每个帧之后不关闭然后重新打开管道,2)调用每帧之后在管道上进行fflush ,3)在帧之间添加延迟.要延迟在Linux上调用 :: usleep(microseconds)(并包括 unistd.h ),在Windows上调用 :: Sleep(milliseconds)和包括 windows.h .

Your code snippet doesn't show how you actually interface with gnuplot, however there are three things you must be sure to do: 1) don't close and then reopen the pipe after each frame, 2) call fflush on the pipe after every frame, and 3) add a delay between frames. To delay on Linux call ::usleep(microseconds) (and include unistd.h), on Windows call ::Sleep(milliseconds) and include windows.h.

关于将动画数据传递到gnuplot的事情是您不知道它是否能跟上进度.因此,潮红和睡眠至关重要.但是我已经用gnuplot搭建了一个示波器,所以我知道它可以很好地工作.

The thing about piping animation data to gnuplot is that you don't know if it is keeping up. So the flush and the sleep are vital. But I have built an oscilloscope out of gnuplot so I know it can work well.

这篇关于从txt文件实时绘制Gnuplot C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆