Gnuplot start to end position as x

前提是你 提交于 2021-01-28 12:11:44

问题


I have a data file test.tsv which consists of three columns:

letter start end

a 15 20

a 40 60

b 124 171

b 237 316

I set y axis to represent the a and b, How can I get lines cover start to end?


回答1:


In a more general case you could do the following which is similar to the solution here.

  1. Create a list of unique keys and use those as the y-axis tics/labels.
  2. Define a lookup function and plot the data accordingly.

You can use the plotting style with vectors but if you want thicker bars instead of lines, I would use the plotting style with boxxyerror because thicker lines also extend in line direction.

Code:

### Schedule plot
reset session

$Data <<EOD
# category  start    end
"a task"  15   20
"b task"  40   60
"c task"  124 171
"d task"  237 316
"c task"   30  35
"a task"  111 197
"d task"   95 103
"b task"   80  93
"special"  10 100
EOD

# create list of unique keys
KeyList = ''
set table $Dummy
    plot $Data u (Key='"'.strcol(1).'"', strstrt(KeyList,Key) ? \
    NaN : KeyList=KeyList.Key." ") w table
unset table

# define function for lookup
Lookup(s) = (Index = NaN, sum [i=1:words(KeyList)] \
    (Index = s eq word(KeyList,i) ? i : Index,0), Index)

set yrange [0.5:words(KeyList)+0.5]

plot $Data u 2:(Index=Lookup(strcol(1))):($3-$2):(0):(Index): \
     ytic(word(KeyList,Index)) w vector nohead lw 4 lc var notitle
### end of code

Result:



来源:https://stackoverflow.com/questions/59179265/gnuplot-start-to-end-position-as-x

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