首页 > 技术文章 > win7下 gnuplot

tofixer 2013-09-11 00:38 原文

之前用FFTW,想在代码中直接就把频谱分析的图画出来,而不是保存到文件,然后用matlab看。所以就想到用gnuplot。

下载gp463-win32-setup.exe, 安装 。 简单运行了其中的demo,还不错。

安装好后,在bin 下 点击  gnuplot.exe
输入 plot sin(x)/x

输入 load "all.dem"  运行所有 demo

但是gnuplot 有C的接口吗?找到以下资料:

查了官方资料,GNUPlot 的确是没有提供C语言的API的。 但我们可以google到很多关于gnuplot的第三方的调用包,不过,我没去试。 但我们应该知道,gnuplot有一个很强大的地方,就是它支持很多的终端输出。 这个,你可以敲入 set term 命令得到证实
于是,我们就可以写一个C程序,重定向输出:
#include<stdio.h>
int main()
{
FILE* fp=popen("binary\\gnuplot","w");
fprintf(fp,"set terminal png \n");
fprintf(fp,"set output '2.png'\n");
fputs("plot x*x with filledcurves, 50-x*x with filledcurves, x*x with line lt 1",fp);
fflush(fp);
pclose(fp);
return 0;
}

试了,不错,只是保存成png后根本就不能缩放和拖动图像了。。

又找,网上都推荐这个:http://ndevilla.free.fr/gnuplot/

结果网址始终打不开,后面又看到这个: http://www.stahlke.org/dan/gnuplot-iostream/ 

里面提到:This is a low level interface, and usage involves manually sending commands to gnuplot using the "<<" operator (so you need to know gnuplot syntax). This is in my opinion the easiest way to do it if you are already comfortable with using gnuplot. If you would like a more high level interface check out the gnuplot-cpp library (http://code.google.com/p/gnuplot-cpp).

这是一个更底层的接口,根据它提供的这个,下了个高层的接口,这个跑example 很顺利。而更底层的那个,可以直接用gnuplot的命令,更加灵活,但是好像要用boost库,所以就没试了。

image

推荐阅读