我有这个文件data.dat
:gnuplot中的数字x轴的直方图?
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
):
set xlabel "X values"
set ylabel "Occurence"
set style data histogram
set style histogram cluster gap 1
set style fill solid border -1
set term png
set output 'hist-v1.png'
set boxwidth 0.9
# attempt to set xtics so they are positioned numerically on x axis:
set xtics ("332" 332, "336" 336, "340" 340, "394" 394, "398" 398, "1036" 1036)
# ti col reads the first entry of the column, uses it as title name
plot 'data.dat' using 2:xtic(1) ti col, '' u 3 ti col, '' u 4 ti col, '' u 5 ti col
,并通过调用:
gnuplot hist-v1.gplot && eog hist-v1.png
生成此图像: image hist-v1.png http://img202.imageshack.us/img202/3974/histv1.png
但是,您可以注意到X轴没有数字缩放 - 它将X值理解为类别(即,它是一个类别轴)。
我可以,hist-v2.gplot
(使用with boxes
)得到具有下列脚本多个数值X轴:
set xlabel "X values"
set ylabel "Occurence"
# in this case, histogram commands have no effect
set style data histogram
set style histogram cluster gap 1
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:2 ti col smooth frequency with boxes, '' u 1:3 ti col smooth frequency with boxes
,并通过调用:产生
gnuplot hist-v2.gplot && eog hist-v2.png
此图像: image hist-v2.png http://img266.imageshack.us/img266/6717/histv2.png
不幸的是,这里的酒吧'重叠',所以很难阅读图表。
有没有办法让数字刻度X轴为hist-v2.png
,但在hist-v1.png
保持并排的“酒吧”的一面?此线程,“Re: Histogram with x axis date error”说,你不能:
但是这将是很难拉x坐标最新出来的数据文件,...
但后来,它指的是一个不同的问题...
谢谢,
干杯!
非常感谢您发布您的解决方案,@ hsxz - 干杯! – sdaau 2011-09-19 19:30:03