Gnuplot的使用

1.download the gnuplot program form www.gnuplot.info
2.unzip the gnuplot.zip to a directory, try to use wgnuplot.exe
3.set the system environment variables to make sure that wgnuplot.exe could be use under cmd
4.write file named filename which could be used in gnuplot(don't forget pause -1 at last otherwise you cant see the graph)
5.use system("wgnuplot.exe filename") in your c++ program,make sure include "stdlib.h" header file.
Edison wang   2009-7-14

gnuplot使用一例
#下面这行设置标题
set title "A demonstration of boxes in mono with style fill pattern"

#下面这一行是用来描述图的每根柱子代表的意义的那个框框的属性。在本例中就是各种search
#其中right top表示位置显示。 Left 表示框子里的字左对齐。 width X用来限定框子大小。
#box X用来表示选用哪种类型的框子--颜色可能不同。 这里在png图里,如果width是0的画,会显得box
#很大,但是,没有关系,如果把它改成jpg格式的话,box正好合适。
set key right top Left reverse width 0 box 3

#下面这两行用来表示x,y轴的意思。引号内的内容会显示在图的轴旁边。
#其中,右边的两个数字表示引号内的内容在图中与x,y轴之间的相对距离。
#第一个0代表水平方向。第二个代表垂直方向。
set xlabel "Number of queries(Hundred)" 0,0
set ylabel "Number of messages" 0,0

#下面一行是用来设置‘柱子’的宽度
set boxwidth 0.9 absolute

#下面两行分别代表不同的画柱子风格。第一种是用颜色去区分。第二种是用斜线来区分柱子。
#第二种打印的话比较好。
#set style fill solid 1.00 border -1
set style fill pattern 3 border -1

set style histogram clustered gap 1 title offset character 0, 0, 0
set datafile missing '-'
set style data histograms
#set xtics border in scale 1,0.5 nomirror rotate by -45 offset character 0, 0, 0
#以下是设置x,y轴的坐标
set xtics   ("5" 0, "10" 1, "15" 2, "20" 3, "25" 4, "30" 5, "35" 6, "40" 7, "45" 8, "50" 9)
set yrange [0 : 25] noreverse nowriteback
#set size 0.7,0.6

set terminal windows
#下面这行语句就是指示柱状图中的每一条的数据是来自'diadata.txt'文件的哪一列.
#eg:u 3 ti col title "Cluster Search" 就是表示title为Cluster Search的'柱子'的数据来自data
#文件的第三列.
plot 'diadata.txt' using 2:xtic(1) ti col title "Recommend Search", '' u 3 ti col title "Cluster Search", '' u 4 ti col title "Simple Search"
set terminal png
#set output "diagram.png"
replot
pause -1

数据文件 文件名为“diadata.txt”
#Number of queries(Hundred)
#Number of messages
Axis    Recommend   Cluster           Simple
5        18.95             19.9487515    20.0672495
10      17.53             19.916748      20.227685
15      15.27             19.580625      20.0324985
20      13.51             19.3010005    19.977125
25      3.06               5.5678747      20.2019375
30      0                    0                     20.0405605     
35      0                   0                     20.0024375
40      0                    0                     20.4801885
45      0                    0                     20.1574375
50      0                    0                     19.584875

posted @ 2009-08-12 06:07  莫忆往西  阅读(395)  评论(0编辑  收藏  举报