这里我有两个数据文件,其中包含模型参数和为它们计算的 RMSE。我想为每个模型分别绘制这些 RMSE,并在其上显示该模型。
请帮忙。
数据文件1:
20 ! # models
1 0.1 ! Theta inc.
3 4 7 ! Approximations
2 ! # layers
GK ! model name
1.0 1.5 ! X-axis values (length varies for other models)
1.0 1.5 ! Y-axis values (length varies for other models)
2
GK_MOD1
1.0 1.5
1.5 1.0
4
Song
2.0 3.0 3.5 4.0
2.5 1.0 0.8 1.3
6
Causse
1.5 1.8 1.9 2.0 2.1 2.2
0.25 0.40 0.60 0.20 0.50 0.55
...
...
数据文件2(重新格式化):
# TKfull GKfull Padefull_3 Padefull_7 TK1 Pade1_3 Pade1_7 Pade2_3 Pade2_7 GK1 Pade3_3 Pade3_7 GK2 PadeEnd_3 PadeEnd_7 GKEnd
GK 0.071 0.028 0.025 0.156 0.023 0.004 0.045 0.012 0.232 0.013 0.090 0.492 0.064 0.064 0.384 0.046
GK_MOD1 0.055 0.030 0.053 0.156 0.012 0.008 0.036 0.050 0.185 0.025 0.169 0.497 0.107 0.125 0.375 0.075
GK_MOD2 0.132 0.042 0.081 0.209 0.035 0.006 0.050 0.051 0.277 0.036 0.267 0.625 0.116 0.192 0.484 0.079
GK_MOD3 0.261 0.067 0.316 0.267 0.066 0.021 0.078 0.138 0.426 0.063 1.137 0.855 0.161 0.810 0.662 0.106
Song 0.082 0.045 0.042 0.163 0.021 0.005 0.027 0.028 0.151 0.050 0.130 0.486 0.156 0.094 0.360 0.106
Song_MOD1 0.087 0.049 0.069 0.171 0.013 0.006 0.025 0.037 0.148 0.051 0.216 0.520 0.175 0.155 0.382 0.120
Song_MOD2 0.109 0.048 0.028 0.179 0.021 0.005 0.030 0.024 0.170 0.048 0.084 0.527 0.161 0.062 0.391 0.110
Song_MOD3 0.073 0.043 0.029 0.145 0.017 0.003 0.024 0.018 0.134 0.049 0.092 0.440 0.156 0.066 0.325 0.105
Cooper_basin 0.031 0.034 0.030 0.105 0.012 0.003 0.016 0.018 0.085 0.055 0.089 0.306 0.139 0.065 0.228 0.093
Cooper_basin_MOD1 0.035 0.017 0.024 0.093 0.016 0.006 0.031 0.034 0.151 0.042 0.083 0.297 0.076 0.063 0.236 0.047
Cooper_basin_MOD2 0.049 0.032 0.032 0.134 0.013 0.005 0.029 0.030 0.150 0.040 0.102 0.412 0.111 0.076 0.312 0.077
Causse2000_1 0.030 0.019 0.020 0.093 0.012 0.004 0.024 0.022 0.121 0.035 0.062 0.286 0.081 0.047 0.219 0.053
Causse2000_2 0.068 0.038 0.014 0.146 0.017 0.001 0.028 0.007 0.151 0.043 0.047 0.444 0.130 0.033 0.332 0.089
Causse2000_3 0.042 0.036 0.023 0.083 0.015 0.005 0.008 0.023 0.156 0.049 0.065 0.195 0.132 0.049 0.177 0.089
Causse2000_4 0.039 0.046 0.046 0.109 0.016 0.003 0.024 0.011 0.049 0.053 0.137 0.318 0.158 0.099 0.230 0.108
Dunkin_1973 0.653 0.641 0.656 0.686 0.703 0.703 0.725 0.239 0.471 0.059 0.434 0.632 0.140 0.353 0.557 0.093
Dunkin_1973_MOD1 0.708 0.624 0.708 0.709 0.694 0.692 0.692 0.760 0.761 0.042 0.785 0.792 0.104 0.773 0.777 0.070
Dunkin_1973_MOD2 0.043 0.029 0.026 0.118 0.050 0.004 0.025 0.023 0.130 0.039 0.082 0.357 0.105 0.061 0.270 0.072
Dunkin_1973_MOD3 0.012 0.014 0.005 0.066 0.011 0.001 0.022 0.002 0.102 0.032 0.017 0.210 0.070 0.012 0.165 0.046
Random 0.033 0.039 0.042 0.114 0.013 0.001 0.017 0.014 0.096 0.047 0.138 0.361 0.140 0.099 0.268 0.097
使用此代码转置数据文件 2,然后通过以下脚本绘制 RMSE 值,如图所示。
Gnuplot 脚本
set terminal png size 800,500 enhanced font "Helvetica,20"
set output 'output.png'
red = "#FF0000"; green = "#00FF00"; blue = "#0000FF"; skyblue =
"#87CEEB";
set yrange [0:2]
set style data histogram
set style histogram cluster gap 1
set style fill solid
set boxwidth 0.9
set xtics format ""
set grid ytics
set xtics rotate by 90 right
set title "A Sample Bar Chart"
plot "RMSE_transpose.dat" using 2:xtic(1) title "GK " linecolor rgb red
图中插图为手绘,即模型本身,如数据文件1所示。
需要帮助:
如何从所有模型的数据文件中获取这样的图, 即 GK、GK_MOD1、GK_MOD2 等,其中单个图像具有模型 name为文件名,如GK_RMSE.png、GK_MOD1_RMSE.png等
如何在每个条形顶部显示Y轴值?
我应该在 Gnuplot 脚本中修改什么才能获得按行和 数据文件 2 中的按列绘图?
这是进一步优化的起点。
正如评论中提到的,gnuplot 不喜欢行中的数据。因此,以原始格式绘制 file1 需要一些额外的行。
一些评论:
colLabels
和rowLabels
)help word
)以按列或行创建图表Xs
和 Ys
Xs
绘制 Ys
与 '+'
对比(检查 help special-filenames
)。with histeps
最接近我所理解的你想要从文件1中获得的风格希望您可以通过检查自行弄清楚其余部分
help ...
。
优化脚本的方法有很多,具体取决于你的具体要求和我不详细了解的数据。
您可以自己回答问题 2 作为作业:请参阅 如何在条形图中每个条形顶部显示实际值?
数据:
SO77228821_1.dat
(x、y 值后不允许有文本)
20 ! # models
1 0.1 ! Theta inc.
3 4 7 ! Approximations
2 ! # layers
GK ! model name
1.0 1.5
1.0 1.5
2
GK_MOD1
1.0 1.5
1.5 1.0
4
Song
2.0 3.0 3.5 4.0
2.5 1.0 0.8 1.3
6
Causse2000_1
1.5 1.8 1.9 2.0 2.1 2.2
0.25 0.40 0.60 0.20 0.50 0.55
SO77228821_2.dat
(OP的file2的缩写,因为OP的file1不完整)
# TKfull GKfull Padefull_3 Padefull_7 TK1 Pade1_3 Pade1_7 Pade2_3 Pade2_7 GK1 Pade3_3 Pade3_7 GK2 PadeEnd_3 PadeEnd_7 GKEnd
GK 0.071 0.028 0.025 0.156 0.023 0.004 0.045 0.012 0.232 0.013 0.090 0.492 0.064 0.064 0.384 0.046
GK_MOD1 0.055 0.030 0.053 0.156 0.012 0.008 0.036 0.050 0.185 0.025 0.169 0.497 0.107 0.125 0.375 0.075
Song 0.082 0.045 0.042 0.163 0.021 0.005 0.027 0.028 0.151 0.050 0.130 0.486 0.156 0.094 0.360 0.106
Causse2000_1 0.030 0.019 0.020 0.093 0.012 0.004 0.024 0.022 0.121 0.035 0.062 0.286 0.081 0.047 0.219 0.053
脚本:
### create graphs from row/column headers
### and graph inset from second file with row-wise data
reset session
FILE1 = "SO/SO77228821_1.dat"
FILE2 = "SO/SO77228821_2.dat"
# get all row-labels and column-labels
set datafile commentschar ''
set datafile separator "\n"
rowLabels = ''
stats FILE2 u ($0==0? colLabels=strcol(1)[2:] : rowLabels=rowLabels.' '.word(strcol(1),1)) nooutput
set datafile separator whitespace
rowLabel(i) = word(rowLabels,i)
colLabel(i) = word(colLabels,i)
FileOut(s) = sprintf("SO/SO77228821_%s_RMSE.png",s)
set boxwidth 0.7
set style fill solid 0.3
set key noautotitle
set term pngcairo size 640,384 font ",10"
# create graphs by rowLabel
do for [row=1:words(rowLabels)] {
set output FileOut(rowLabel(row))
set multiplot
set size 1,1
set origin 0,0
set xrange[*:*]
set yrange[0:*]
set offset 0.5,0.5,0,0
set xtic rotate by 90 right noenhanced
set title rowLabel(row) noenhanced
plot for [i=1:words(colLabels)] FILE2 every ::row-1::row-1 u (i+1):colLabel(i):xtic(colLabel(i)) w boxes lc "red" notitle
set datafile separator "\n"
c=NaN
stats FILE1 u (word(strcol(1),1) eq rowLabel(row) ? c=$0 : 0, c+1==$0 ? Xs=strcol(1) : c+2==$0 ? Ys=strcol(1) : 0 ) nooutput
set datafile separator whitespace
set xrange[word(Xs,1):word(Xs,words(Xs))]
set yrange[0:*]
set offset 0,0,0,0
set xtic rotate by 0 center
set samples words(Xs)
set size 0.4,0.4
set origin 0.08,0.45
unset title
plot '+' u (i=int($0+1),x0=real(word(Xs,i))):(y0=real(word(Ys,i))) w histeps lc "blue" lw 2
unset multiplot
set size 1,1
set origin 0,0
}
# create graphs by colLabel
do for [col=1:words(colLabels)] {
set output FileOut(colLabel(col))
set title colLabel(col) noenhanced
set xrange[*:*]
set yrange[0:*]
plot FILE2 u 0:col+1:xtic(1) w boxes lc "web-green" notitle
}
set output
### end of script
结果:(只是生成的许多文件中的两个示例)