一,基础篇:
在 linux 命令提示符下运行 gnuplot 命令启动,输入 quit 或 q 或 exit 退出。
1. plot 命令
gnuplot> plot sin(x) with line linetype 3 linewidth 2或
gnuplot> plot sin(x) w l lt 3 lw 2 %用线画,线的类型(包括颜色与虚线的类型)是 3,线的
宽度是 2,对函数 sin(x)作图
gnuplot> plot sin(x) with point pointtype 3 pointsize 2或
gnuplot> plot sin(x) w p pt 3 ps 2 %用点画,点的类型(包括颜色与点的类型)是 3,点的大
小是 2
gnuplot> plot sin(x) title 'f(x)' w lp lt 3 lw 2 pt 3 ps 2 %同时用点和线画,这里 title ‘f(x)’表示图
例上标'f(x)',如果不用则用默认选项
gnuplot> plot sin(x) %此时所有选项均用默认值。如果缺某一项则将用默认值
gnuplot> plot ‘a.dat’ u 2:3 w l lt 3 lw 2 %利用数据文件 a.dat 中的第二和第三列作图
顺便提一下,如这里最前面的两个例子所示,在 gnuplot 中,如果某两个词,按字母先后顺
序,前面某几个字母相同,后面的不同,那么只要写到第一个不同的字母就可以了。如
with,由于没有其它以 w 开头的词,因此可以用vw代替,line 也可以用 l代替。
2、同时画多条曲线
gnuplot> plot sin(x) title ‘sin(x)’ w l lt 1 lw 2, cos(x) title ‘cos(x)’ w l lt 2 lw 2%两条曲线是用
逗号隔开的。画多条曲线时,各曲线间均用逗号隔开就可以了。
以上例子中是对函数作图,如果对数据文件作图,将函数名称换为数据文件名即可,但要
用单引号引起来。
3、关于图例的位置
默认位置在右上方。
gnuplot> set key left %放在左边,有 left和 right 两个选项
gnuplot> set key bottom %放在下边,只有这一个选项;默认在上边
gnuplot> set key outside %放在外边,但只能在右面的外边,以上三个选项可以进行组合。
如:
gnuplot> set key left bottom %表示左下边,还可以直接用坐标精确表示图例的位置,如
gnuplot> set key 0.5,0.6 %将图例放在 0.5,0.6 的位置处
4、关于坐标轴
gnuplot> set xlabel ‘x’ %x 轴标为‘x’
gnuplot> set ylabel ‘y’ %y 轴标为’y’
gnuplot> set ylabel ‘DOS’ tc lt 3 %其中的 tc lt 3 表示’DOS’的颜色用第三种颜色。
gnuplot> set xtics 1.0 %x 轴的主刻度的宽度为 1.0,同样可以为 y 轴定义 ytics
gnuplot> set mxtics 3 %x 轴上每个主刻度中画 3 个分刻度,同样可以为 y 轴定义 mytics
评论3
最新资源