gnuplot:如何添加从 0 开始的错误栏?
gnuplot: How can I add error bars that start at 0?
我想在直方图中添加从 0 开始的误差线。
类似 this and this 的示例,但它们都从条形图的峰值开始。
这就是我目前制作条形图的方式:
set style histogram clustered
unset title
set xlabel "X"
set ylabel "Y"
set boxwidth 1
set style fill solid
set term png
set output "figure.png"
plot [-0.5:4.5][0:10] "data.dat"using 2:xtic(1) title "Title 1" with histograms fillstyle pattern 1, \
"" using 3 title "Title 2" with histograms fillstyle pattern 2, \
"" using 4 title "Title 3" with histograms fillstyle pattern 3
我可以将第 4 列添加到我的 data.dat 文件中,它将具有误差线的高度,但我不知道绘制它的正确方法。
编辑:
set style fill solid 1.0
w = 0.15
set boxwidth 0.3
set key top right
set xlabel "X"
set ylabel "Y"
set xrange[0.5:5.9]
set yrange[0:300]
set xtics 1
plot "data.dat" u (-w):2 w boxes lc rgb "read" ti "Title 1", \
'' u (+w):3 w boxes lc rgb "green" ti "Title 2", \
'' u (+w*3):4 w boxes lc rgb "blue" ti "Title 3", \
'' u (-w):5 w impulses dt 3 lw 3 lc rgb "black" ti "Title 4", \
'' u (-w):5 w p pt 7 ps 1 lc rgb "black" not, \
'' u (+w):6 w impulses dt 3 lw 3 lc rgb "black" not, \
'' u (+w):6 w p pt 7 ps 1 lc rgb "black" not, \
'' u (+w*3):7 w impulses dt 3 lw 3 lc rgb "black" not, \
'' u (+w*3):7 w p pt 7 ps 1 lc rgb "black" not, \
'' u 0:(NaN):xtic(1) not
为什么不画呢"manually"with boxes
和with impulses
和with points
?您没有提供示例数据,所以我创建了一些数据。
例如像这样。也许有更短的方法。
编辑: 使用 xtic 字符串而不是数字。
代码:
### manual histogram and percentile line
reset session
# n MedianX MedianY Perc90x Perc90y
$Data <<EOD
A 7.1 6.2 20.3 16.4
B 8.1 7.2 22.3 17.4
C 9.1 8.2 24.3 18.4
D 10.1 9.2 26.3 19.4
E 11.1 10.2 28.3 20.4
EOD
set style fill solid 1.0
w = 0.15
set boxwidth 0.3
set key top left
set xrange[-0.5:4.5]
set xtics 1
plot $Data u ([=10=]-w):2 w boxes lc rgb "red" ti "Median x", \
'' u ([=10=]+w):3 w boxes lc rgb "blue" ti "Median y", \
'' u ([=10=]-w):4 w impulses dt 3 lc rgb "black" ti "90th Percentile", \
'' u ([=10=]-w):4 w p pt 7 ps 1 lc rgb "black" not, \
'' u ([=10=]+w):5 w impulses dt 3 lc rgb "black" not, \
'' u ([=10=]+w):5 w p pt 7 ps 1 lc rgb "black" not, \
'' u 0:(NaN):xtic(1) not
### end of code
结果:
添加:(对于 3 列和 with errorlines
而不是 impulses
和 points
)
代码:
### manual histogram and percentile line
reset session
# n MedianX MedianY MedianZ Perc90x Perc90y Perc90z
$Data <<EOD
A 7.1 6.2 5.3 20.4 16.5 12.6
B 8.1 7.2 6.3 22.4 17.5 13.6
C 9.1 8.2 7.3 24.4 18.5 14.6
D 10.1 9.2 8.3 26.4 19.5 15.6
E 11.1 10.2 9.3 28.4 20.5 16.6
EOD
set style fill solid 1.0
w = 0.20
set boxwidth 0.20
set key top left
set xrange[-0.5:4.5]
set xtics 1
plot $Data u ([=11=]-w):2 w boxes lc rgb "red" ti "Median x", \
'' u ([=11=]):3 w boxes lc rgb "blue" ti "Median y", \
'' u ([=11=]+w):4 w boxes lc rgb "web-green" ti "Median z", \
'' u ([=11=]-w):(0):(0):5 w errorlines ls 0 ti "90th Percentile", \
'' u ([=11=]):(0):(0):6 w errorlines ls 0 not, \
'' u ([=11=]+w):(0):(0):7 w errorlines ls 0 not, \
'' u 0:(NaN):xtic(1) not, \
### end of code
结果:
我想在直方图中添加从 0 开始的误差线。
类似 this and this 的示例,但它们都从条形图的峰值开始。
这就是我目前制作条形图的方式:
set style histogram clustered
unset title
set xlabel "X"
set ylabel "Y"
set boxwidth 1
set style fill solid
set term png
set output "figure.png"
plot [-0.5:4.5][0:10] "data.dat"using 2:xtic(1) title "Title 1" with histograms fillstyle pattern 1, \
"" using 3 title "Title 2" with histograms fillstyle pattern 2, \
"" using 4 title "Title 3" with histograms fillstyle pattern 3
我可以将第 4 列添加到我的 data.dat 文件中,它将具有误差线的高度,但我不知道绘制它的正确方法。
编辑:
set style fill solid 1.0
w = 0.15
set boxwidth 0.3
set key top right
set xlabel "X"
set ylabel "Y"
set xrange[0.5:5.9]
set yrange[0:300]
set xtics 1
plot "data.dat" u (-w):2 w boxes lc rgb "read" ti "Title 1", \
'' u (+w):3 w boxes lc rgb "green" ti "Title 2", \
'' u (+w*3):4 w boxes lc rgb "blue" ti "Title 3", \
'' u (-w):5 w impulses dt 3 lw 3 lc rgb "black" ti "Title 4", \
'' u (-w):5 w p pt 7 ps 1 lc rgb "black" not, \
'' u (+w):6 w impulses dt 3 lw 3 lc rgb "black" not, \
'' u (+w):6 w p pt 7 ps 1 lc rgb "black" not, \
'' u (+w*3):7 w impulses dt 3 lw 3 lc rgb "black" not, \
'' u (+w*3):7 w p pt 7 ps 1 lc rgb "black" not, \
'' u 0:(NaN):xtic(1) not
为什么不画呢"manually"with boxes
和with impulses
和with points
?您没有提供示例数据,所以我创建了一些数据。
例如像这样。也许有更短的方法。
编辑: 使用 xtic 字符串而不是数字。
代码:
### manual histogram and percentile line
reset session
# n MedianX MedianY Perc90x Perc90y
$Data <<EOD
A 7.1 6.2 20.3 16.4
B 8.1 7.2 22.3 17.4
C 9.1 8.2 24.3 18.4
D 10.1 9.2 26.3 19.4
E 11.1 10.2 28.3 20.4
EOD
set style fill solid 1.0
w = 0.15
set boxwidth 0.3
set key top left
set xrange[-0.5:4.5]
set xtics 1
plot $Data u ([=10=]-w):2 w boxes lc rgb "red" ti "Median x", \
'' u ([=10=]+w):3 w boxes lc rgb "blue" ti "Median y", \
'' u ([=10=]-w):4 w impulses dt 3 lc rgb "black" ti "90th Percentile", \
'' u ([=10=]-w):4 w p pt 7 ps 1 lc rgb "black" not, \
'' u ([=10=]+w):5 w impulses dt 3 lc rgb "black" not, \
'' u ([=10=]+w):5 w p pt 7 ps 1 lc rgb "black" not, \
'' u 0:(NaN):xtic(1) not
### end of code
结果:
添加:(对于 3 列和 with errorlines
而不是 impulses
和 points
)
代码:
### manual histogram and percentile line
reset session
# n MedianX MedianY MedianZ Perc90x Perc90y Perc90z
$Data <<EOD
A 7.1 6.2 5.3 20.4 16.5 12.6
B 8.1 7.2 6.3 22.4 17.5 13.6
C 9.1 8.2 7.3 24.4 18.5 14.6
D 10.1 9.2 8.3 26.4 19.5 15.6
E 11.1 10.2 9.3 28.4 20.5 16.6
EOD
set style fill solid 1.0
w = 0.20
set boxwidth 0.20
set key top left
set xrange[-0.5:4.5]
set xtics 1
plot $Data u ([=11=]-w):2 w boxes lc rgb "red" ti "Median x", \
'' u ([=11=]):3 w boxes lc rgb "blue" ti "Median y", \
'' u ([=11=]+w):4 w boxes lc rgb "web-green" ti "Median z", \
'' u ([=11=]-w):(0):(0):5 w errorlines ls 0 ti "90th Percentile", \
'' u ([=11=]):(0):(0):6 w errorlines ls 0 not, \
'' u ([=11=]+w):(0):(0):7 w errorlines ls 0 not, \
'' u 0:(NaN):xtic(1) not, \
### end of code
结果: