GNUPLOT QA
GNUPLOT QA
怎样交互式执行
terminal命令行输入gnuplot命令,进入交互模式

怎样用单行命令执行
gnuplot -e ‘cmd1;cmd2’,因为直接在term中绘图是需要-e option;

gnuplot -p -e ‘cmd1;cmd2’
弹出绘图窗口需要加-p option,只是用-e option弹窗会立刻消失,-p -e顺序不能颠倒,-pe或-ep都会报错

怎样执行gnuplot’脚本‘
gnuplot脚本没有明确的扩展格式,通常可以使用.p .plt .gnuplt作为扩展名,gnuplot -p script.plt


怎样设置坐标轴数值范围
- plot [x1,x1] [y1,y2] function,绘制函数时通过方括号设定x/y数值范围
- set xrange/yrange [num1,num2],set命令设定x/y数值范围
怎样绘制asicii字符表示的图标
set term dumb
怎样绘制并保存图像为png格式
set term png
set output “result.png”


怎样设置绘图板尺寸
set term xxx size num1,num2


怎样设置输入文件数据分隔符
gnuplot默认以空格作为数据分隔符
gnuplot file separator site:stackoverflow.com
set datafile separator "char"
怎样在一个绘图板绘制多个函数
绘制的各个函数用逗号分隔

怎样隐藏key
unset key

怎样把key放在绘图外
set key outside

怎样从文件读取数据绘图
文件名用双引号括起来,using x:y, 1代表第一列x轴数据,2代表第二列y轴数据
set term dumb
plot "data.dat" using 1:2

绘制第一组数据,gnuplot默认以点的方式绘图

绘制多组数据
set term dumb
plot "data.dat" using 1:2,"data.dat" using 1:3

怎样使用其他数据表达风格
plot "data.dat" using 1:2 with lines,"data.dat" using 1:3 with linespoints

plot "data.dat" using 1:2 with lines,"data.dat" using 1:3 with boxes

怎样为数据加上title
plot "data.dat" using 1:2 title "DATA-1" with lines,"data.dat" using 1:3 with boxes

## 怎样省略文件名
第二个及之后的数据和第一个数据用的同一份文件可以用双引号表示
plot "data.dat" using 1:2 title "DATA-1" with lines,"" using 1:3 with boxes
怎样save/restore term
set terminal push #保存当前终端
set term dumb #切到dumb term
set term pop #恢复之前使用的终端
怎样使用index
文件中可能包含多组数据集,数据集的分组用两行空行区分,数据集的分组从0开始
index {int:start}[:{int:end}][:{int:step}]

gnuplot -e 'set term dumb;plot "index.dat" index 0 using 1:2 with lp'

gnuplot -e 'set term dumb;plot "index.dat" index 2 using 1:2 with lp'

gnuplot -e 'set term dumb;plot "index.dat" index 1:2 using 1:2 with lp'
# 绘制数据集1和数据集2

gnuplot -e 'set term dumb;plot "index.dat" index 0:2:2 using 1:2 with lp'
# 绘制数据集0和数据集2

怎样使用every
数据可能是有规律的存储在文件中
every {int:step}[::{int:start}[::{int:end}]]
#使用两个冒号

gnuplot -e 'set term dumb;plot "every.dat" every 2 using 1:2 with lp'

gnuplot -e 'set term dumb;plot "every.dat" every 2::0 using 1:2 with lp'
start行号缺省默认为0,所以行号从0开始

gnuplot -e 'set term dumb;plot "every.dat" every 2::1 using 1:2 with lp'


浙公网安备 33010602011771号