首页 GNUPLOT使用手册

GNUPLOT使用手册

举报
开通vip

GNUPLOT使用手册 GNUPLOTGNUPLOTGNUPLOTGNUPLOT使用手册 中央研究院计算中心 ASPACASPACASPACASPAC 计划 aspac@beta.wsl.sinica.edu.tw 技术报告: 94002 1994年 5月 20日 Version:2.1 ChapterChapterChapterChapter 1.1.1.1. IntroductionIntroductionIntroductionIntroduction GNUPLOT是在1986年由 Colin kelley 和 Thoma...

GNUPLOT使用手册
GNUPLOTGNUPLOTGNUPLOTGNUPLOT使用手册 中央研究院计算中心 ASPACASPACASPACASPAC 计划 aspac@beta.wsl.sinica.edu.tw 技术 报告 软件系统测试报告下载sgs报告如何下载关于路面塌陷情况报告535n,sgs报告怎么下载竣工报告下载 : 94002 1994年 5月 20日 Version:2.1 ChapterChapterChapterChapter 1.1.1.1. IntroductionIntroductionIntroductionIntroduction GNUPLOT是在1986年由 Colin kelley 和 Thomas Williams 所发展的绘图公用程式,可 将数学函数或数值资料以平面或立体的图形画在不同种类终端机或绘图输出装置上。目前已 广泛地被人们使用,在 Internet网路上尚有 newsgroup --- comp.graphics.gnuplot 作为大家交 换心得或学习的园地。此 newsgroup将许多问 快递公司问题件快递公司问题件货款处理关于圆的周长面积重点题型关于解方程组的题及答案关于南海问题 集成 FAQ (Frequently Answered Questions) 并定期刊载。 GNUPLOT 是一个命令导向的交谈式绘图程式(command-driven interactive function plotting program)。GNUPLOT执行使用者输入的每一项命令,可逐步设定或修改绘图环境。 它以图形表达数据或函数,使我们藉由图形 做更进一步的分析。 在此以 GNUPLOT 3.5版为讨论主体。而本篇文章所引用范例皆整理自 GNUPLOT demo 中范例。在本篇文章中,而本篇文章中的图例亦引用自子目录 demo中的范例。在本篇文章 中,第二章、介绍 GNUPLOT的基本观念。第三章、介绍 GNUPLOT的计算环境。 第四章 、 设定绘图环境的设定。第五章、介绍绘图指令。第六章、介绍输入及输出部分。第七章、介 绍杂项指令。第八章、介绍由 GNUPLOT所绘出不同类别的例子。第九章、结论。我们期 望读者能由此使用手册中了解 GNUPLOT,进一步绘出期望的结果。 ChapterChapterChapterChapter 2.2.2.2. GettingGettingGettingGetting startstartstartstart 2.12.12.12.1 HowHowHowHow totototo getgetgetget GNUPLOTGNUPLOTGNUPLOTGNUPLOT GNUPLOT可在 UNIX、OS/2、MSWINDOW、MSDOS等作业系统上执行,若你所使 用的计算机内没有 gnuplot此项软体。可透过 anonymous FTP由下述地方取得: 1 GNUPLOT Source code: phi.sinica.edu.tw:/pub/math/gnuplot35/src.zip NCTUCCCA.NCTU.edu.tw:/PC/simtel/plot/gpt35exe.zip ftp.dartmouth.edu:/pub/gnuplot/gnuplot3.5.tar.Z 2 MS-Windows binaries code: phi.sinica.edu.tw:/pub/math/gnuplot35/win.zip NCTUCCCA.NCTU.edu.tw:/PC/simtel/plot/gpt35exe.zip oak.oakland.edu:/pub/msdos/plot/gpt35exe.zip 3 OS/2 2.x binaries code: phi.sinica.edu.tw:/pub/math/gnuplot35/os2.zip NCTUCCCA.NCTU.edu.tw:/PC/os2/2_x/unix/gnuplt35.zip ftp-os2.nmsu.edu:/os2/2_x/unix/gnuplt35.zip 4 MS-DOS 32bit binariey code: phi.sinica.edu.tw:/pub/math/gnuplot35/dos.zip 或者透过邮寄服务(ftp-mail server)取得。方法为送一封信 ftpmail@ftp.dartmouth.edu,信的内 容为: open cd pub/gnuplot mode binary get gnuplot3.5.tar.Z quit 即可取得 uuencoded版本的 gnuplot source (compressed tar file)。 2.22.22.22.2 StartingStartingStartingStarting upupupup GNUPLOTGNUPLOTGNUPLOTGNUPLOT 以下是使用GNUPLOT绘出三角函数 sin(x)与数值资料图形及 sin(x)*cos(y)函数3D图形 的命令。 % gnuplot GNUPLOT unix version 3.5 patchlevel 3.50.1.17, 27 Aug 93 last modified Fri Aug 27 05:21:33 GMT 1993 Copyright(C) 1986 - 1993 Thomas Williams, Colin Kelley Send comments and requests for help to info-gnuplot@dartmouth.edu Send bugs, suggestions andmods to bug-gnuplot@dartmouth.edu Terminal type set to 'x11' gnuplot> plot sin(x), 'data.demo' gnuplot> splot sin(x)*cos(y) gnuplot> quit % 档案 data.demo为一数据资料档案,每一行描述一点座标位置。 内容如下: # file : data.demo -20.000000 -3.041676 -19.000000 -3.036427 -18.000000 -3.030596 . . . 执行 GNUPLOT程式时,GNUPLOT首先检查是否设定环境参数 DISPLAY,若有则依 其设定。当其确定为 X环境时,将输出模式设定为 X11。输入 plot sin(x), 'data.demo' 产生图1 结果 --- 以线段绘出三角函数 sin(x);以点绘出档案 data.demo内各点座标。 图1111: Plotting sin(x), data file - data.demo 接者输入 splot sin(x)*cos(y) 产生图 2 结果 --- 以纵横各 10条线组成的网格画出 sin(x)*cos(y)的图形。而 quit 指令 结束 gnuplot程式。 图2222: PlottingPlottingPlottingPlotting sin(x)*cos(y)sin(x)*cos(y)sin(x)*cos(y)sin(x)*cos(y) 由此例中,可知 GNUPLOT具有下列特色 : • 不需复杂的设定即可画出平面或立体的数学函数或数值资料图形。 • 自动调整或可由使用者调整 X轴、Y轴及 Z轴的范围和各轴的标点,显示完整地结 果。 • 将函数名称自动标示在右上角。 • 以不同的线条颜色或不同的图样明显地区别不同的函数图形。 • GNUPLOT有许多内建函数,亦可自建函数。 在 X 环境下,GNUPLOT如同其他 X client程式一般,可接受许多参数。如 gnuplot -font 8x13bold # 设定字形为 8x13bold。 gnuplot -geometry 900x700 # 设定视窗的长为 900 pixel 宽为 700 pixel。 gnuplot -bg black # 设定背景颜色为黑色。 等。 2.32.32.32.3 ProgrammingProgrammingProgrammingProgramming stylestylestylestyle 我们依据一般绘制数学函数或数值资料可能发生的步骤。 提出一份 GNUPLOT程式撰 写程序,如图3。 图3333: ProgrammingProgrammingProgrammingProgramming flowflowflowflow chartchartchartchart • 定义常数及函数:定义常数及函数,使程式模组化及易于了解。 • 设定绘图环境:GNUPLOT绘图之前已预先设定许多绘图参数(见附录 A)。 这些设定做为 GNUPLOT绘图时的参考,包括座标轴、文字说明、图形显示范围、3D 图形投影到平面的投影角度、取样点数、绘制图形所用的图案等等的设定。我们可根据个人 所需逐一改变绘图参数。GNUPLOT的参数设定可见附录 A,或在 GNUPLOT程式内,键 入 show all 命令得知目前的绘图环境设定情况。 gnuplot> show all . . autoscaling is x: ON, y: ON, z: ON border is drawn boxwidth is auto point clip is OFF drawing and clipping lines between inrange and outrange points . . . • 绘图:在定义数学函数或设定绘图环境之后,接著是绘出数学函数或数值资 料图形 。 GNUPLOT 提供操作方便的绘图指令 --- plot(2D) 或 splot(3D), 具有丰富的参数设定,可 由参数的设定做个别调整。 • 产生输出结果:在终端机上绘出结果后,可经由一些步骤而产生不同输出装 置所需 的输出语言,得到输出结果。 依照上述过程,可快速地画出图形。剩下的步骤就是细心的调整绘图环境参 数或修改 函数方程式、常数等,即可得到满意的结果。 在图4中第1行由 # 符号开始为注解,第2至第7行定义方程式及设定参数,第8行之后是 设定绘图的状态,第18行将图画出,其馀是将图以 PostScript格式存于'npn.ps'档案中。其中 设定绘图参数为: • set dummy Vbe :gnuplot 一般以 x 为变数,代表横轴上的变数。GNUPLOT可设 定成其它名称以增加可读性。此例设定为 Vbe (表示 base emmitter 之间的电位差)。 • set grid : 将座标平面绘上格子。 • set title : 改变 title 名称,将 title 改成 "Mutual Characteristic of a Transistor"。 • set xlable, set ylable :设定横轴与纵轴名称,将横轴名称定为 "Vbe (base emitter voltage)",将纵轴名称定为 "Ic(collector current)"。 • set xrange, set yrange :设定横轴与纵轴显示范围,此调整显示范围至最 想观察的 区域。 • set key :设定所绘的函数名称所放置的座标位置。 图4444: ExampleExampleExampleExample : NPNNPNNPNNPNMutualMutualMutualMutual CharacteristicCharacteristicCharacteristicCharacteristic GNUPLOT指令可分成五部份 : • 使用者自定函数、常数 :在绘图前定义函数或常数,产生绘图所需的函数。 • 设定绘图环境:GNUPLOT的绘图环境由一组参数构成,由设定参数可改变绘图环 境。 • 设定输出环境:GNUPLOT提供许多种输出装置的输出语言,可由命令设定输出装 置。 • 绘图 :GNUPLOT提供操作方便的绘图指令 --- plot(splot)。 • 杂项 :不属于前四类范围的指令,如系统相关指令。 接下来的几章就针对 GNUPLOT指令加以描述。 ChapterChapterChapterChapter 3.3.3.3. Constants,Constants,Constants,Constants, OperatorsOperatorsOperatorsOperators andandandand FunctionsFunctionsFunctionsFunctions 我们在此讨论 GNUPLOT中数字、常数、运算子及函数。 3.13.13.13.1 NumberNumberNumberNumber GNUPLOT表示数字可分成整数、实数及复数三类: • 整数:GNUPLOT 与 C 语言相同,采用4 byte 储存整数。故能表示-2147483647至 +2147483647之间的整数。 • 实数:能表示约6或7位的有效位数,指数部份为不大于308的数字。亦即 正数 : 约 4.19e-307 至 1.67e+307 零 : 0 负数 : 约 -1.67e+308 至 -4.19e-307 • 复数 : 以{,}表示 --- 复数。其中为此复数的实数部份,为虚 数部份,此两部份均以实数型态表示。 如 3 + 2i 即以{3,2}表示。 GNUPLOT储存数字的原则为,若能以整数方式储存则以整数储存数字,不然以实数方 式储存,其次以复数方式储存。例如在 GNUPLOT执行 print 1/3*3 print 1./3*3 分别得到 0和 1.0的结果。这是因前者使用整数计算,而后者采用实数计算的结果。执 行 print 1234.567 print 12345 + 0.56789 print 1.23e300 * 2e6 print 1.23e300 * 2e8 分别得到 1234.57、12345.6、2.46e+304 和 undefined value 的结果。这些例子是受到实 数的有效位数和所能表现最大数字的限制。这是我们要注意的。 3.23.23.23.2 OperatorsOperatorsOperatorsOperators GNUPLOT所提供如 C 语言般的运算子(operator)。所有的运算子均可做用在整数、实 数或复数上。运算子可分作 Binary Operator和 Unary Operator,就是分别作用在两个或一个 数学式子上,数学式子可为数字或方程式。 UnaryUnaryUnaryUnary OperatorsOperatorsOperatorsOperators Symbol Example Explanation - -a unary minus ~ ~a * one's complement ! !a * logical negation ! a! * factorial 表 1111: UnaryUnaryUnaryUnary OperatorsOperatorsOperatorsOperators BinaryBinaryBinaryBinary OperatorsOperatorsOperatorsOperators Symbol Example Explanation ** a**b exponentiation * a*b multiplication / a/b division % a%b * modulo + a+b addition - a-b subtraction == a==b equality != a!=b inequality & a&b * bitwise AND ^ a^b * bitwise exclusive OR | a|b * bitwise inclusive OR && a&&b * logical AND || a||b * logical OR ?: a?b:c * ternary operation 表2222: BinaryBinaryBinaryBinary OperatorsOperatorsOperatorsOperators 3.33.33.33.3 FunctionsFunctionsFunctionsFunctions 在 GNUPLOT中函数的参数可以是整数,实数或是复数。表3是 GNUPLOT所提供的函 数。GNUPLOT画条件函数的方法可由图9中观察, 其采用类似 C语言的语法,画出函数 Function Auguments Returns abs(x) any absolute value of x, |x|; same type abs(x) complex length of x, sqrt( real(x)^2 + imag(x)^2 ) acos(x) any 1/cos(x) (inverse cosine) in radians arg(x) complex the phase of x in radians asin(x) any 1/sin(x) (inverse sin) in radians atan(x) any 1/tan(x) (inverse tangent) in radians besj0(x) radians J0 Bessel function of x besj1(x) radians J1 Bessel function of x besy0(x) radians Y0 Bessel function of x besy1(x) radians Y1 Bessel function of x ceil(x) any smallest integer not less than x (real part) cos(x) radians cos x, cosine of x cosh(x) radians cosh x, hyperbolic cosine of x erf(x) any Erf(real(x)), error function of real(x) erfc(x) any Erfc(real(x)), 1.0 - error function of real(x) exp(x) any exponential function of x floor(x) any largest integer not greater than x (real part) gamma(x) any Gamma(real(x)), gamma function of real(x) ibeta(p,q,x) any Ibeta(real(p,q,x)), ibeta function of real(p,q,x) inverf(x) any inverse error function of real(x) igamma(a,x) any Igamma(real(a,x)), igamma function of real(a,x) imag(x) complex imaginary part of x as a real number invnorm(x) any inverse normal distribution function of real(x) int(x) real integer part of x, truncated toward zero lgamma(x) any Lgamma(real(x)), lgamma function of real(x) log(x) any ln(x), natural logarithm (base e) of x log10(x) any log(x), logarithm (base 10) of x norm(x) any normal distribution (Gaussian) function of real(x) rand(x) any Rand(real(x)), pseudo random number generator real(x) any real part of x sgn(x) any 1 if x>0, -1 if x<0, 0 if x=0. imag(x) ignored sin(x) radians sin(x), sine of x sinh(x) radians sinh(x), hyperbolic sine x sqrt(x) any sqrt(x), square root of x tan(x) radians tan(x), tangent of x tanh(x) radians tanh(x), hyperbolic tangent of x 表3333:GNUPLOTGNUPLOTGNUPLOTGNUPLOT functionsfunctionsfunctionsfunctions 3.43.43.43.4 User-definedUser-definedUser-definedUser-defined functionsfunctionsfunctionsfunctions andandandand ConstantsConstantsConstantsConstants 在 GNUPLOT中,使用者可自定函数。函数可有1至5个变数。其定义函数的语法如下: ( {, {, ...}}) = 而使用者定义常数的语法如下: = 下面举一些例子: # 常数 w 为 2。 w = 2 # 常数 q 为小于但最接近 tan(pi/2 - 0.1) 的整数。 q = floor(tan(pi/2 - 0.1)) # 函数 f(x) 为 sin(w*x),其中 w 为常数。 f(x) = sin(w*x) # 函数 sinc(x) 为 sin(pi*x)/(pi*x)。 sinc(x) = sin(pi*x)/(pi*x) # 函数 delta(t) 为脉冲函数。 delta(t) = (t == 0) # 函数 ramp(t) 当其小于零为零,当其大于零为斜率等于 1 的直线。 ramp(t) = (t > 0) ? t : 0 # 函数 min(a,b) 取两者中较小的数。 min(a,b) = (a < b) ? a : b comb(n,k) = n!/(k!*(n-k)!) len3d(x,y,z) = sqrt(x*x+y*y+z*z) GNUPLOT已定义的常数仅有 pipipipi (pi = 3.14159)。 ChapterChapterChapterChapter 4.4.4.4. PlottingPlottingPlottingPlotting enviromentenviromentenviromentenviroment 如第二章所述,只要键入 plot sin(x), 'data.demo' 即可得到图1的结果。GNUPLOT自动 调整 X轴、Y 轴的显示范围,使图形显示在适当的位置;选择不同的颜色、图形,用以区 别不同的函数或数值资料……也就是 GNUPLOT自动调整其所需的绘图环境。若我们需要 一些特别的,如在3D中加入 contour、设定消去隐藏线、改变 X轴、Y轴的座标点名称…… 等,可由改变绘图参数而改变之。本章说明这些绘图参数设定的方法与功能。 GNUPLOT的绘图参数可分作下列几项: 名称 说明 座标轴(axis) 改变座标轴的外观,如 linear或 logscale等。 标题(label) 设定文字说明或线条,产生时间等。 座标系统 改变座标系统。 图形处理 处理欲绘出的图形,使其易于观察。 3D 调整3D图形的参数。 输出 设定输出的选。 杂项 不属于上述几项的设定。 我们可用 set命令去设定这些参数及用 show命令去察看这些参数。show all则是察看所 有的参数设定。本章各节依序说明绘图参数的设定: 4.14.14.14.1AxisAxisAxisAxis 绘图参数在设定座标轴方面的参数可分为变数名称、标点、网格、显示范围、 座标轴 显示方式与显示与否等六方面的设定: 功能 绘图参数名称 变数名称设定 dummy 标点设定 format, tics, xdtics, xmtics, xtics, ydtics, ymtics, ytics, zdtics, zmtics, ztics, ticlevel 网格设定 grid 座标显示方式 logscale 显示范围设定 autoscale, rrange, trange, urange, vrange, xrange, yrange, zrange 座标轴显示与否 xzeroaxis, yzeroaxis 1 变数名称设定 :一般以 x为横轴上的变数。可用 dummy 设定为其它的名称,所绘 函数的变数名称亦随之改变。如 set dummy t 将自变数改为 t,图8、图17、图20均改变自变 数名称。 2 标点设定 :设定标点的显示方式与格式。由 format 此项参数设定显示格式,其语 法为 : set format {} {""} show format # 显示各轴标点显示的型式 3 其中 axis为 xxxx、yyyy、zzzz、xyxyxyxy 或预设为 xyxyxyxy。format-string 为描述每一标点的格式,可接 受如 C语言中 printf对数字的 f、e、g三种格式化描述,亦可加入文字(必须少于100字)。以 下举一些例子: set format xy "%.2e" set format x "%3.0f cm" 4 显示方式由 tics、xtics、... 等设定。 xtics 是对 X 座标轴上的标点做设定。如起始点、结束点、间隔或在轴上特定点放特定 的名称。其语法为: set xtics { {, {, }} | {({"
本文档为【GNUPLOT使用手册】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_434470
暂无简介~
格式:pdf
大小:383KB
软件:PDF阅读器
页数:38
分类:互联网
上传时间:2011-07-13
浏览量:294