gnuplot中带有数字x轴的直方图?

gnuplot中带有数字x轴的直方图?,gnuplot,histogram,numeric,Gnuplot,Histogram,Numeric,我将此文件命名为data.dat: Xstep Y1 Y2 Y3 Y4 332 1.22 0.00 0.00 1.43 336 5.95 12.03 6.11 10.41 340 81.05 81.82 81.92 81.05 394 11.76 6.16 10.46 5.87 398 0.00 0.00 1.51 1.25 1036 0.03 0.00 0.00 0.00 我可以使用此脚本将此数据绘制为直方图,hist-v1.gplot(使用set style data histogram)

我将此文件命名为
data.dat

Xstep Y1 Y2 Y3 Y4
332 1.22 0.00 0.00 1.43
336 5.95 12.03 6.11 10.41
340 81.05 81.82 81.92 81.05
394 11.76 6.16 10.46 5.87
398 0.00 0.00 1.51 1.25
1036 0.03 0.00 0.00 0.00
我可以使用此脚本将此数据绘制为直方图,
hist-v1.gplot
(使用
set style data histogram
):

并致电:

gnuplot hist-v1.gplot && eog hist-v1.png
gnuplot hist-v2.gplot && eog hist-v2.png
gnuplot hist-v2b.gplot && eog hist-v2b.png
此图像生成于:

但是,您可以注意到,X轴没有按数字缩放-它将X值理解为类别(即,它是类别轴)

我可以通过以下脚本获得一个更为数字化的X轴,
hist-v2.gplot
(使用带框的
):

并致电:

gnuplot hist-v1.gplot && eog hist-v1.png
gnuplot hist-v2.gplot && eog hist-v2.png
gnuplot hist-v2b.gplot && eog hist-v2b.png
此图像生成于:

不幸的是,这些条在这里“重叠”,因此很难读取图表

有没有办法使数字刻度X轴保持如
hist-v2.png
中所示,但将“条”与
hist-v1.png
中的“条”并排保持?此线程表示您不能:

但是要从数据文件中提取x坐标日期是很困难的

但是,它指的是一个不同的问题

谢谢


干杯

好的,在阅读了一点
gnuplot
帮助之后,直方图样式似乎“总是”将x轴解释为顺序条目/类别-因此,实际上,似乎没有办法获得具有直方图样式的数字轴

然而,事实证明,
$
可以引用一个列,这些列可以用于实际“重新定位”第二个(
频率与框
样式)示例中的条;因此,使用此代码作为
hist-v2b.gplot

set xlabel "X values"
set ylabel "Occurence"
set style fill solid border -1
set term png
set output 'hist-v2.png'
set boxwidth 0.9
set xr [330:400]
# here, setting xtics makes them positioned numerically on x axis:
set xtics ("332" 332, "336" 336, "340" 340, "394" 394, "398" 398, "1036" 1036)  
# 1:2 will ONLY work with proper xr; since we have x>300; xr[0:10] generates "points y value undefined"!
plot 'data.dat' using ($1-0.5):2 ti col smooth frequency with boxes, '' u ($1-0.25):3 ti col smooth frequency with boxes, '' u ($1+0.25):4 ti col smooth frequency with boxes, '' u ($1+0.5):5 ti col smooth frequency with boxes
并致电:

gnuplot hist-v1.gplot && eog hist-v1.png
gnuplot hist-v2.gplot && eog hist-v2.png
gnuplot hist-v2b.gplot && eog hist-v2b.png
此图像生成于:

。。。这正是我一开始想要的

只是一个小提示-我最初想使用带有内联数据的脚本;对于这样的设置,必须将其编写为

plot '-' using ($1-0.5):2 ti col smooth frequency with boxes, '-' u ($1-0.25):3 ti col smooth frequency with boxes
Xstep Y1 Y2 Y3 Y4
332 1.22 0.00 0.00 1.43
336 5.95 12.03 6.11 10.41
340 81.05 81.82 81.92 81.05
394 11.76 6.16 10.46 5.87
398 0.00 0.00 1.51 1.25
1036 0.03 0.00 0.00 0.00
end
Xstep Y1 Y2 Y3 Y4
332 1.22 0.00 0.00 1.43
336 5.95 12.03 6.11 10.41
340 81.05 81.82 81.92 81.05
394 11.76 6.16 10.46 5.87
398 0.00 0.00 1.51 1.25
1036 0.03 0.00 0.00 0.00
end
。。。也就是说,数据必须多次输入,因为它是从stdin输入的-这个问题将在中讨论

干杯

PS:由于图上有相当大的空间,如果我们能指定单独的x轴范围,那就太好了;讨论内容如下:


使用“长方体”打印样式打印直方图时,正确设置长方体宽度非常重要。在我的一篇博客文章中,我谈到了这一点。如果有兴趣,请点击