Gnuplot 是一种免费分发的绘图工具,可以移植到各种主流平台,也可以使用编程语言产生的数据进行绘图
1.配置gnuplot
为了能在命令窗口运行gnuplot,需要将gnuplot.exe路径添加到windows路径中(Windows10为例),将gnuplot安装好了以后,记住它的安装路径
方法为:
控制面板->高级系统设置->环境变量->系统变量->Path
命令窗口显示:
2.gnuplot绘图常识
gnuplot绘图程序中对线型(linetype)、点型(pointtype)、线条宽度(linewidth)、点大小(pointsize)、图样(style)都有相应的设定值,具体设置如下:
(1)线型(linetype )。在此类型中主要设置线条的颜色,具体对应如下:
n | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
---|---|---|---|---|---|---|---|
linetype | black | red | green | blue | pink | 浅蓝 | yellow |
(2)点型(pointtype)。此类型用于设置点得形状,可分为14中,具体对应如下:
n | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
pointtype | 无 | + | × | * | □ | ■ | ○ | ● | △ | ▲ | ▽ | ▼ | ◇ | ◆ |
(3)w lp
即 with linepoint ,把数据点描出来,并且将数据点连线。with 后的属性参数有多个选择,对应不同的作图方式(style)。在指令窗口输入 hplp with 或者 help style就可以查到可供选择的 style 参数。常用的作图方式参数及对应含义如下表所示:
style参数 | 简写 | 对应含义 |
---|---|---|
line | l | 将相邻点连线 |
point | p | 将每一点用一符号标记 |
linepoint | lp | 将每一点用一符号标记,并将相邻点连线 |
impulses | i | 将每一点画一垂直线至x轴 |
steps | st | 用垂直线及水平线各一条来连接两点,形成台阶状图形 |
boxes | boxes | 以x坐标为中心做柱状图 |
errorbars | e | 对每一点坐标值(x,y),画一由(x,ylow) 至(x,yhigh) 的线段。并在线段两端做上 tic mark |
boxerrorbars | boxerrorbars | 结合errorbars与boxes两者功能 |
(4)lt 1
即 linetype 1 ,规定了连线的类型,-1对应黑虚线,0对应黑虚线,大于0的整数对应不同颜色的实线。1为紫色,2为绿色,3为蓝色,4为橙色、5为黄色、6为深蓝色、7为红色、8为黑色,大于8的数字对应的颜色与其对8的余数对应的颜色相同。
(5)lw 2
即 linewidth 2 ,规定了线的宽度,数字越大,线越宽。
(6)pt 4
即 pointtype 4,规定了标记点的类型
2.gnuplot绘图显示
(1)绘图1
gnuplot> set title "study gnuplot" //建立标题
gnuplot> set xlabel "Angle" //x轴标题
gnuplot> set ylabel "sin(angle)"//y轴标题
gnuplot> set key top left//关键字位置
gnuplot> set key box
gnuplot> plot [-pi:pi] sin(x) title "sinone" with linespoints pointtype 5,cos(x) t 'cosone' w boxes lt 4// 绘图范围、点的类型以及线条连线
gnuplot>
效果:
(2)绘图2
gnuplot> set title "study gnuplot"
gnuplot> set xlabel "Angle"
gnuplot> set ylabel "sin(angle)"
gnuplot> set xrange [-pi:pi]
gnuplot> set size 1,1
gnuplot> set origin 0,0
gnuplot> set multiplot //建立多图像
multiplot> set size 0.5,0.5
multiplot> set origin 0,0.5
multiplot> plot sin(x)
multiplot> set size 0.5,0.5
multiplot> set origin0,0
^
unrecognized option - see 'help set'.
multiplot> set origin 0,0
multiplot> plot 1/sin(x)
multiplot> set size 0.5,0.5
multiplot> set origin 0.5,0.5
multiplot> plot cos(x)
multiplot> set size 0.5,0.5
multiplot> set origin 0.5,0
multiplot> plot 1/cos(x)
multiplot>
效果: