linux:gnuplot
gnuplot 在终端绘图
ASCII 终端绘图
gnuplot set term dumb plot sin(x) q
- 数据文件
test.csv
123 145 143 156 156 178 165 189 168 199 176 203
- 绘图命令
gnuplot gnuplot> set term dumb Terminal type set to 'dumb' Options are 'feed size 79, 24' gnuplot> plot 'test.csv' u ($0):1 w lp t 'c1', 'test.csv' u ($0):2 w lp t 'c2' gnuplot> q
- 直接执行命令绘图
gnuplot -e "set term dumb; plot 'test.csv';" gnuplot -e 'set term dumb; plot "test.csv" u ($0):1 w lp t "c1", "test.csv" u ($0):2 w lp t "c2";'
gnuplot 常用命令
gnuplot> h plot # 查看帮助文档 gnuplot> set term dumb # 切换输出模式 gnuplot> !cat text2.csv # 执行 shell 命令 gnuplot> p x (绘制 y = x 函数) gnuplot> plot [-pi:pi] sin(x) # 设置坐标 gnuplot> splot [-10:10] [-20:20] x**2+y # 绘制简单的三位函数图, 比如绘制z(x,y)=x2+y gnuplot> plot sin(1.5 * x) gnuplot> plot 'test.csv' title 'c1' # 设置图例名称 gnuplot> plot 'test.csv' using 1:2 # 选取数据列绘图 gnuplot> plot 'test.csv' with lines # 选择线条风格 gnuplot> plot 'test.csv' with linespoints gnuplot> plot 'test.csv' with points gnuplot> plot 'test.csv' using ($0):1, 'test.csv' using ($0):2 # 使用行号作为横轴 # 设置标题 gnuplot> set title 'Test Title' gnuplot> set xlabel 'Times' gnuplot> set ylabel 'Cost/ms' gnuplot> set arrow 1 from 1,200 to 0.2,208 # 设置注释箭头 gnuplot> show arrow set key at 2, 0.5 # 设置注释图例 set label "y=x" at 0, 208 # 设置注释文本
gnuplot 编写脚本
demo01
- 脚本文件
demo01.plt
set encoding utf8 # set terminal pdfcairo enhanced size 4in,3in font "Times New Roman,12" # set output "demo01.pdf" set term dumb set tics nomirror set xtics norangelimit set key box inside set key at 2.5, 0.95 set xlabel 'time' set ylabel 'velocity' plot "data01.txt" using 1:2 with lines ls 1 lw 2 title "pos1", \ "" using 1:3 with linespoints ls 2 lw 1 pointtype 12 ps 1 title "pos2", \ replot reset print "Done!"
- 数据文件
data01.txt
1 0.2893 0.3061 2 0.3636 0.2857 3 0.2562 0.2041 4 0.1983 0.1633 5 0.4463 0.5714 6 0.6033 0.5714 7 0.9008 0.8571 8 0.2727 0.5714 9 0.7355 0.8367 10 0.1322 0.1837
- 绘制命令
gnuplot demo01.plt
demo02
- 脚本文件
demo02.plt
# set terminal pngcairo transparent enhanced font "arial,10" fontscale 1.0 size 600, 400 # set output 'histograms.2.png' set encoding default # set terminal emf size 800,600 font "Times New Roman,12" # set output "pic2.emf" set term dumb set boxwidth 0.9 absolute set style fill solid 1.00 border lt -1 set key inside right top vertical Right noreverse noenhanced autotitle nobox set style histogram clustered gap 1 title textcolor lt -1 # set minussign # set datafile missing '-' set style data histograms set xtics border in scale 0,0 nomirror rotate by -45 autojustify set xtics norangelimit set xtics () set xlabel '时间' set ylabel '速度' plot 'data02.txt' using 2:xtic(1) ti col , '' u 3 ti col reset print "Done!"
- 数据文件
data02.txt
时间 pos1 pos2 1 0.4824 0.4845 2 0.5941 0.5876 3 0.8882 0.9175 4 0.3588 0.7423 5 0.7647 0.6186 6 0.1471 0.1546
- 绘制命令
gnuplot demo02.plt
linux/gnuplot.txt · 最后更改: 2024/01/18 18:41 由 pengge
评论