Gnuplot 简单使用

  • Post author:
  • Post category:其他


一 、最简单的例子

gnuplot>plot sin(x)

其中

gnuplot>

为命令提示符,不是命令的一部分,

二 、加入设置




1

、设置

x



y

坐标的范围



改变坐标范围


set xrange [xmin:xmax]                   set yrange [ymin:ymax]



gnuplot

决定坐标轴范围

gnuplot>set autoscale

也可以只在本次绘图中设置,使用

plot   [xmin:xmax]   [ymin:ymax] f(x)

,例如:

gnuplot>plot   [0:5]   [-2:2] sin(x)

,结果如下


可只设置

x



y

的范围,如只设置

x

范围




gnuplot>plot   [0:5]  sin(x)

只设置

y

的范围


gnuplot>plot   [] [0:1]  sin(x)

只设置一边,如设置

y

为小于

0

gnuplot>plot   [] [:0]  sin(x)

结果:



2

、设置坐标轴名称


gnuplot>set xlabel ‘xlabel’ ; set ylabel ‘ylabel’   ;  plot sin(x)

可以在一行写多个命令,命令间用分号隔开

取消坐标轴名称设置


gnuplot>unset xlabel

gnuplot>unset ylabel


3

、设置对数坐标

设置为对数坐标

set  logscale



设置

x



y

轴为对数坐标


gnuplot>set  logscale x


gnuplot>set  logscale y

取消对数坐标

unset  logscale


4

、设置绘图标题


gnuplot>set title ‘title’

gnuplot>plot sin(x)

取消绘图标题设置

unset title


5

、同时绘制多个函数


gnuplot>plot f1(x),f2(x),……fn(x)

,例如:




gnuplot>plot sin(x),x

,结果:




6

、为曲线设置标题


gnuplot>plot f(x) title ‘title’

例如:


gnuplot>plot sin(x) title ‘y=sin(x)’,x title ‘y=x’

结果:


7

、设置曲线标题的放置位置


gnuplot>set key x,y

其中

x,y

为横、纵坐标,例如:




gnuplot>set key   8,-0.8


gnuplot> plot [-10:10] [-1:1] sin(x) title ‘sin’


将文本




sin’

放置在

(8,-0.8)

坐标处,结果:





将曲线标题放置到默认位置,使用命令:


gnuplot>set  key  default

设置不显示曲线标题,使用名令

unset  key


可设置绘图标题框


gnuplot>set key box

效果如下


取消设置绘图标题框,使用命令

set  key  nobox


8

、添加网格


gnuplot>set grid;plot cos(x)

取消网格,使用命令

unset grid

转载于:https://www.cnblogs.com/nuistlr/archive/2012/06/20/2555871.html