在直方图(群集)中,如何根据条件将垂直文本替换为某些条形? [英] In a Histogram chart(clustered), How to put vertical text in place of some of the bars, depending on condition?
问题描述
在Gnuplot中,我使用的是直方图(群集),但并非所有数据点都具有有效值.在这些地方,我想用垂直文字不能服务"代替该栏.我该怎么办?
In Gnuplot, I am using a Histogram chart(clustered), but not all data points have valid values. In those places, I want to replace the bar with a vertical text saying "Cannot Serve". How do I do it?
我当前的代码:
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
type "magnetic" "electric"
"high load" 12000 12721.033920
"med load" 15620.011886 15783.706215
"low load" 15636.000000 16254.000000
推荐答案
这是一种超级实用的方法.我修改了文件以添加"NaN":
This is a super hacky way to do this. I modified your file to add a "NaN":
"high load" NaN 12721.033920
"med load" 15620.011886 NaN
"low load" 15636.000000 16254.000000
现在,我绘制所有内容with boxes
,其中相对于记录在数据文件中的显示顺序(列0)计算每个框的位置.它是在此处手动"定义的,但是您应该能够编写一个函数,该函数根据记录的数量和每个记录的列数(例如,从stats
获得的)来获取xrange
和框分隔. boxwidth
还将取决于这些值.
Now I plot everything with boxes
where the position of each box is calculated with respect to the order in which the records appear in the data file (column 0). It is "manually" defined here, but you should be able to write a function that gets the xrange
and the box separation based on the number of records and the number of columns per record as obtained from stats
for example. Also the boxwidth
would depend on those values.
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
这篇关于在直方图(群集)中,如何根据条件将垂直文本替换为某些条形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!