目录
安装
Ubuntu:
sudo apt-get update
sudo apt-get install gnuplot. # ubuntu
brew install gnuplot # mac, 安装Homebrew:https://brew.idayer.com/guide/start/
代码查看工具:
- 带有
RunMe
插件的Notepad++
- 带有
Code Runner
、Rainbow Brackets
和Gnuplot
扩展的VS Code。
相关内容
注意事项
- gnuplot只能利用文件中列数据绘制图;
图例中设置特殊字符
设置方法,可以参考下表设置,将需要的内容替换为{/Symbol \编码}
, 以做左括号为例: {/Symbol \050}
, 右括号{/Symbol \051}
,空格{/Symbol \040}
,对于空格占位可能很小,可以效果不行可以用多个,例如{/Symbol \040\040\040}
。
摘抄自: https://blog.csdn.net/nccccc12345/article/details/120507271
在gnuplot中,如果想要显示特殊字符或者一些稍微复杂的文字标签,在set term后面需要加上enhanced,使用enhanced文本模式,还有一部分特殊字符如果想要显示,需要使用Symbol字体。
Symbol字体列表:(图片来源:http://blog.sina.com.cn/s/blog_6f0425db0100pkbk.html
颜色设置
参考:https://www.cnblogs.com/luntai/p/6200779.html
gnuplot颜色设置
可以在gnuplot
中通过show colorname
查看预定义的颜色,如下:
gnuplot> show colorname
There are 111 predefined color names:
white #ffffff = 255 255 255
black #000000 = 0 0 0
dark-grey #a0a0a0 = 160 160 160
red #ff0000 = 255 0 0
web-green #00c000 = 0 192 0
web-blue #0080ff = 0 128 255
dark-magenta #c000ff = 192 0 255
dark-cyan #00eeee = 0 238 238
dark-orange #c04000 = 192 64 0
dark-yellow #c8c800 = 200 200 0
royalblue #4169e1 = 65 105 225
...
使用方法:lc rgb "black"
:
set style line 1 lc rgb "gray"
set style line 1 lc rgb "black"
set style line 2 lc rgb "red"
set style line 3 lc rgb "green"
set style line 4 lc rgb "blue"
set style line 5 lc rgb "cyan"
set style line 6 lc rgb "magenta"
set style line 7 lc rgb "yellow"
set style line 8 lc rgb "dark-yellow"
set style line 9 lc rgb "navy"
坐标刻度10^3科学计数法
摘抄自https://blog.csdn.net/weixin_44385985/article/details/108851412
这里推荐可以用自定义坐标刻度set ytics ("" 0, "" 2500 1,"5 {/Symbol \264} 10^3" 5000, "" 7500 1,"10{/Symbol \264} 10^3" 10000,"" 12500 1,"15{/Symbol \264} 10^3" 15000,"" 17500 1,"20{/Symbol \264} 10^3" 20000,"" 22500 1,"25{/Symbol \264} 10^3 " 25000,"" 27500 1) set mytics
2,这里是我自定义的主刻度与分刻度
具体自定义为 “标记” 刻度位置 0主刻度/1分刻度,{/Symbol \264}
是特殊符号代码具体要啥自己去查
改后效果为
一些例子
柱状图
reset
set terminal postscript eps enhanced color
set yrange [0:1.2]
#set xlabel "Batch size" font ", 25" offset 2,-2
set ylabel "Normalized Time" font ", 25" offset 0,0
set size 1, 1
set bmargin 2 # 下边距
set lmargin 0 # 左边距
set rmargin 0
set size ratio 1 # 这个和size需要对应调整
set tics font ",25"
set key font ", 25"
set key width 1 # 调整图例行间隔
set key samplen 2 # 调整图例中线段示例长度
set style fill solid
set style histogram clustered gap 3 # 每组柱子之间的间隔
set xtics rotate by 0 offset 1,0
set boxwidth 1 # 柱子的宽度
set key top right vertical center # 图例的位置和排列方式, horizontal/vertical, https://gnuplot.sourceforge.net/docs_4.2/node192.html
array A[7] = [1, 2, 3, 4, 5, 6, 7]
pat = "'1' '2' '3' '4' '5' '6' '7'"
# 指定位置加标签
set label '37.89%' at 0.95,1.00 #font ",16"
set label '61.53%' at 0.6,1.04
# test1
set yrange [0:1.5]
set output "test1.eps"
plot for [COL=2:8:1] 'test1.data' using COL:xticlabels(1) w histograms lc A[COL-1] fill pattern COL+3 title columnheader(COL)
set output
test
:
time A\_1 B C D E F G_1
#X 1 1.367746262 1.261010919 0.983982631 1.006753025 1.027936996 0.976415817
#Y 1 0.271416778 0.133735505 0.764568934 0.210152219 0.591376135 0.607696895
#X 1 0.799362521 0.844447444 0.996907971 0.891042011 0.673143813 0.719292275
U 1 0.643467863 1.02264713 0.20741493 1.026231217 0.934759393 0.567866802
V 1 0.473391796 0.752759157 0.166390894 0.962157148 0.538629592 0.912852416
折线图
每条折线对应数据文件中的一列
数据,注意gnuplot不允许按行加载数据,所以如果你的每条线长短不一致时,只能将每个条线对应的数据分别写入不同的文件中,即,一个文件一列。
code:
reset
set terminal postscript font "Times-Roman,25" eps enhanced color
set size 1.3, 0.65
#set yrange [0.5:0.97]
#set xrange[0:15]
set bmargin -3
#set xtics ("0" 0,"200" 200, "400" 400, "600" 600,"3400" 800,"3600" 1000,"3800" 1200)
set size ratio 0.5
set ylabel "Value" font ",25" offset 2.5, 0
set xlabel "Step" font ",25" offset 0, 1
set key bottom right font ",20"
# set xtics ("0" 0, "1" 1,"3" 3,"5" 5,"7" 7,"10" 10, "15" 15)
set xtics offset