In a Histogram chart(clustered), How to put vertical text in place of some of the bars, depending on condition?

a 夏天 提交于 2019-12-11 05:47:01

问题


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?

My current code:

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

data file contains:

type "magnetic" "electric"
"high load" 12000 12721.033920
"med load" 15620.011886 15783.706215
"low load" 15636.000000 16254.000000


回答1:


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

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



来源:https://stackoverflow.com/questions/38845229/in-a-histogram-chartclustered-how-to-put-vertical-text-in-place-of-some-of-th

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!