使用gnuplot画图

step1 准备数据cwnd.dat
step2 创建画图脚本cwnd.gnuplot
step3 写入cwnd.gnuplot

# 生成xx.eps矢量图,可以转换为.pdf等格式
set terminal postscript eps enhanced size 5, 4 color solid linewidth 3  # terminal postscript eps将图画到eps文件中; enhanced使用增强模式, size 5, 4 横纵比为5:4,color彩色图,solid实线,linewidth 3线(包括边框)的粗细为3磅 (front 'times, 32')
set output "dos.eps" # 输出图片名称

set xrang [-10:10] # x轴范围
set xlabel 'Time (ms)' # x轴标签
set xtics -10,2,10 # x轴增量为2

set yrang [-120:120] 
set ylabel 'Cwnd' offset 0.8, 0.0 # 将y轴标签移动(0.8,0.0)
set ytics -120,40,120 

# 设置画布尺寸
set bmargin at screen 0.18 # 图片框下面预留18%
set tmargin at screen 0.96 # 顶上留出4%
set lmargin at screen 0.18
set rmargin at screen 0.96

unset key # 删除图例
set arrow 1 from 0,-120 to 0,120 linestyle 0 nohead # 设置1号参考线, linestyle 0 虚线(1实线),没有箭头
plot "cwnd.dat" using 1:2 with lines linecolor '#FF0000' linewidth 2, "cwnd.dat" using 1:(-$3) with lines linecolor '#0000FF' linewidth 2 #using 1:2 使用数据的1,2行对应x,y, (-$3)第三列数据乘-1

step4 根据脚本画图,输入命令

gnuplot cwnd.gnuplot

step5 显示图片

evince dos.eps &

to-do

  • 参考线设置
  • 柱状图

参考

https://www.bilibili.com/video/BV1Vh411U7cK?spm_id_from=333.337.search-card.all.click


版权声明:本文为bajiaoyu517原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。