Gnuplot 在柱状图(群集)中,如何根据条件将垂直文本放置在某些条形图的位置?

Gnuplot 在柱状图(群集)中,如何根据条件将垂直文本放置在某些条形图的位置?,gnuplot,histogram,Gnuplot,Histogram,在Gnuplot中,我使用的是直方图(集群),但并非所有数据点都具有有效值。在这些地方,我想用一条竖直的文字来代替酒吧,上面写着“不能服务”。我该怎么做 我当前的代码: set style data histogram set style histogram cluster gap 2 set boxwidth 0.9 set xtic rotate by -45 scale 0 set output "test.pdf" plot 'data.txt' using 2:xtic(1) fs

在Gnuplot中,我使用的是直方图(集群),但并非所有数据点都具有有效值。在这些地方,我想用一条竖直的文字来代替酒吧,上面写着“不能服务”。我该怎么做

我当前的代码:

set style data histogram
set style histogram cluster gap 2
set boxwidth 0.9
set xtic rotate by -45 scale 0 

set output "test.pdf"
plot 'data.txt' using 2:xtic(1) fs pattern 1 ti col, '' u 3 fs pattern 2 ti col
数据文件包含:

类型“磁性”“电气”
“高负荷”12000 12721.033920
“中等负荷”15620.011886 15783.706215
“低负荷”15636.000000 16254.000000


这是一个超级黑客的方式来做到这一点。我修改了您的文件以添加“NaN”:

现在,我用方框绘制所有内容
,其中每个方框的位置是根据记录在数据文件中的显示顺序计算的(第0列)。它在这里是“手动”定义的,但是您应该能够编写一个函数,该函数可以根据记录数和每个记录的列数(例如从
stats
获得)来获取
xrange
和框分隔。此外,
boxwidth
将取决于这些值

set xtic rotate by -45 scale 0
ymax = 20000
set yrange [0:ymax]

nrecords = 3
ncolumns = 2

set xrange [0:nrecords+1]

# Calculate boxwidth from available space per column
gap = 1./ncolumns/5.
width = 1./ncolumns/2.-gap/2.
set boxwidth width

plot "data.txt" u ($0+1.-width/2.-gap/2.):($2) w boxes t "data1", \
     "" u ($0+1.+width/2.+gap/2.):($3) w boxes t "data2", \
     "" u ($0+1.):(ymax/6.):(stringcolumn(2) eq "NaN" ? \
     "Cannot serve" : ""):xtic(1) w labels rotate by 90 offset \
     first -width/2.-gap/2.,0 not, \
     "" u ($0+1.):(ymax/6.):(stringcolumn(3) eq "NaN" ? "Cannot serve" \
     : ""):xtic(1) w labels rotate by 90 offset first width/2.+gap/2.,0 not

没有有效值的文件是什么样子的?这一个在任何地方都有有效值,只需
设置yrange[0:]
即可查看“高负载”栏。答案将取决于这些无效值的外观。“无效”值将看起来像“NaN”或“Na”,而不是一个数字。抱歉,如果没有一些非常老套的解决方案,我无法找出这一个。。。
set xtic rotate by -45 scale 0
ymax = 20000
set yrange [0:ymax]

nrecords = 3
ncolumns = 2

set xrange [0:nrecords+1]

# Calculate boxwidth from available space per column
gap = 1./ncolumns/5.
width = 1./ncolumns/2.-gap/2.
set boxwidth width

plot "data.txt" u ($0+1.-width/2.-gap/2.):($2) w boxes t "data1", \
     "" u ($0+1.+width/2.+gap/2.):($3) w boxes t "data2", \
     "" u ($0+1.):(ymax/6.):(stringcolumn(2) eq "NaN" ? \
     "Cannot serve" : ""):xtic(1) w labels rotate by 90 offset \
     first -width/2.-gap/2.,0 not, \
     "" u ($0+1.):(ymax/6.):(stringcolumn(3) eq "NaN" ? "Cannot serve" \
     : ""):xtic(1) w labels rotate by 90 offset first width/2.+gap/2.,0 not