Gnuplot 简单使用

来源:互联网 发布:用java调用weka j48 编辑:程序博客网 时间:2024/04/30 06:53

http://www.duke.edu/~hpgavin/gnuplot.html

 

基本语法:

 

plot and splot are the primary commands in Gnuplot. They plotfunctions and data in many many ways. plot is used to plot 2-d functions and data, while splot plots 3-d surfaces and data.

Syntax:



plot {[ranges]}



{[function] | {"[datafile]" {datafile-modifiers}}}



{axes [axes] } { [title-spec] } {with [style] }



{, {definitions,} [function] ...}







几个简单的例子:








For example, try:



gnuplot> plot sin(x)/x

gnuplot> splot sin(x*y/20)

gnuplot> plot sin(x) title 'Sine Function', tan(x) title 'Tangent'

 

从文件中读取数据,并作图:

Discrete data contained in a file can be displayed by specifying the nameof the data file (enclosed in quotes) on the plot or splot command line. Data files should have the data arranged in columns ofnumbers. Columns should be separated by white space (tabs or spaces)only, (no commas). Lines beginning with a # character are treatedas comments and are ignored by Gnuplot. A blank line in the data fileresults in a break in the line connecting data points.

For example your data file, force.dat , might look like:

以空白字符作为行列分割, 空行表示数据分段

      # This file is called   force.dat



# Force-Deflection data for a beam and a bar



# Deflection Col-Force Beam-Force



0.000 0 0



0.001 104 51



0.002 202 101



0.003 298 148



0.0031 290 149



0.004 289 201



0.0041 291 209



0.005 310 250



0.010 311 260



0.020 280 240



You can display your data by typing:

      gnuplot>  plot  "force.dat" using 1:2 title 'Column', /



"force.dat" using 1:3 title 'Beam'



Do not type blank space after the line continuation character, "/" .

Your data may be in multiple data files. In this case you may makeyour plot by using a command like:

也可以从不同的文件中读取数据

      gnuplot>  plot  "fileA.dat" using 1:2 title 'data A', /



"fileB.dat" using 1:3 title 'data B'



For information on plotting 3-D data, type: 关于3d请看帮助

      gnuplot>  help splot datafile



改变图片的风格:
















后面跟with来改变做出的图形样式













gnuplot> plot "force.dat" using 1:2 title 'Column' with lines


, /



"force.dat" u 1:3 t 'Beam' w linespoints










Plots may be displayed in one of eight styles:



lines, points, linespoints, impulses, dots, steps, fsteps, histeps,



errorbars, xerrorbars, yerrorbars, xyerrorbars, boxes, boxerrorbars,



boxxyerrorbars, financebars, candlesticks or vector











设置全局的格式:













使用set





命令来设置样式,用replot





命令来显示改变情况







Create a title: > set title "Force-Deflection Data"



Put a label on the x-axis: > set xlabel "Deflection (meters)"



Put a label on the y-axis: > set ylabel "Force (kN)"



Change the x-axis range: > set xrange [0.001:0.005]



Change the y-axis range: > set yrange [20:500]



Have Gnuplot determine ranges: > set autoscale



Move the key: > set key 0.01,100



Delete the key: > unset key



Put a label on the plot: > set label "yield point" at 0.003, 260



Remove all labels: > unset label



Plot using log-axes: > set logscale



Plot using log-axes on y-axis: > unset logscale; set logscale y



Change the tic-marks: > set xtics (0.002,0.004,0.006,0.008)



Return to the default tics: > unset xtics; set xtics auto







一个图片上,画多个图






set multiplot; # get into multiplot mode

set size 1,0.5;

set origin 0.0,0.5; plot sin(x);

set origin 0.0,0.0; plot cos(x)

unset multiplot # exit multiplot mode





输出文件:








set terminal jpeg

set output "your_output_file"

plot sin(x)/x

这样输出的文件就是jpeg的格式了。







原创粉丝点击