gnuplot_i的简短介绍
------------------------------------
gnuplot_i正式应该称为gnuplot管道,是一种友好的编程方式实现用C语言调用gnuplot画图.
画图的具体步骤操作如下:
1通过一个gnuplot_ctrl型指针,打开gnuplot,调用方式为gnuplot_init(),如下
gnuplot_ctrl * h ;
h = gnuplot_init() ;
h将被作为gnuplot工作区的指针,通过其它库函数调用h(自己也可以给指针取不同的名字,以下用h作指针变量)
2.图像参数设置如下
gnuplot_setstyle(h, style)
(设置画图风格)
gnuplot_set_xlabel(h, label)
设置x轴坐标
gnuplot_set_ylabel(h, label)
设置Y轴坐标
例子:
gnuplot_setstyle(h, "impulses") ;
gnuplot_set_xlabel(h, "my X label") ;
gnuplot_set_ylabel(h, "my Y label") ;
最有用的套路,应该是gnuplot_cmd(),它允许你给gnuplot传送特征的字符串,如下所示:
gnuplot_cmd(h, command, ...)
例子:
char myfile[] = "/data/file_in.dat" ;
int i ;
gnuplot_cmd(h, "plot '%s'", myfile);
for (i=0 ; i<10 ; i++) {
gnuplot_cmd (h, "plot y=%d*x", i);
}
接下来的命令,需要输出给postscript这种脚本语言文件curve.ps完成
gnuplot_cmd(h, "set terminal postscript") ;
gnuplot_cmd(h, "set output \"curve.ps\"") ;
3. 一些画图命令:
gnuplot_plot_slope()
画一条斜线
gnuplot_plot_equation()
画一个函数图像
gnuplot_plot_x()
画用户给定数据的第一维,作为X轴,画图(单变量画图)
gnuplot_plot_xy()
画两个变量的图
gnuplot_resetplot()
清除之前的画图
4. 关闭gnuplot指针变量:关闭此变量是非常重要的,否则其它画图产生的临时文件将不会在缓存中删除
gnuplot_close(h) ;
See examples of gnuplot_i use in the provided files
'example.c' and 'anim.c'.
Some more points before you start using gnuplot_i
-------------------------------------------------
gnuplot_i is completely free software. Use it for
whatever you want to do with it without any fee, and do not
hesitate to send feedback to me if you wish:
<ndevilla@free.fr>
If you can do it, I would appreciate a mention somewhere
that you are using 'gnuplot_i' in your application.
Something like:
"This software uses the gnuplot_i library written by
N.Devillard <ndevilla@free.fr>
If you are using gnuplot_i for a web-based
application, you can also add a link to the gnuplot home
page:
http://ndevilla.free.fr/gnuplot/
注意:当在一个程序中需要写打开多个画图对话框的时候,要注意函数与所打开对话框的对应关系
例如:
h1 = gnuplot_init() ;
h2 = gnuplot_init() ;
gnuplot_plot_equation(h1, "sin(x)", "sine on first session");
gnuplot_plot_equation(h2, "log(x)", "log on second session") ;
sleep(3) ;
gnuplot_close(h1) ;
gnuplot_close(h2) ;
警告:不要忘记关闭对话框!
编译运行examples
-------------------------------
可以使用已经提供的Makefile文件进行编译, 或者以如下方式进行编译:
To compile the gnuplot_i module:
% cc -I. -c gnuplot_i.c
编译两examples:
% cc -o example example.c gnuplot_i.o
% cc -o anim anim.c gnuplot_i.o
使用Makefile进行编译:
% make
% make tests
Try it out to see if it works:
% test/anim -- Will show an animated sine wave
% test/example -- Will show various functions in use
% test/sinepng -- Will generate a PNG file with a sine wave
N. Devillard