Mkn
Mkn

Reputation: 638

plot data at same Yrange

I have this data :

Channel1 3 5
Channel1 1 2
Channel2 1 3

My goal is to plot the values of Channel1 on the same line , I have tried to get inspiration from this question : Plot date and time interval and duration but Channel1 is present 2 times on Y-axis

set terminal png size 1920,240 transparent
set output "plot.png"
$DATA << EOD
Channel1 3 5
Channel1 1 2
Channel2 1 3
EOD
set style fill solid
boxwidth = 0.5
plot $DATA using (($2+$3)/2.):0:(($3-$2)/2.):(boxwidth/2.):yticlabels(1) w boxxyerrorbars notitle

enter image description here

Upvotes: 0

Views: 46

Answers (1)

theozh
theozh

Reputation: 25714

If your keyword is simply Channel+<number> you can define a function to extract this number. In the example below, e.g. Channel 3 is missing, so there will be a gap. If your keywords are arbitrary then you would have to build a unique list of this keywords (something like a hash-table or dictionary) and assign numbers. This would also be possible in gnuplot but a bit more "complicated".

Code:

### a simple chart with keywords
reset session

$Data <<EOD
Channel1 3.0 5.0
Channel2 1.0 2.0
Channel1 1.1 2.2
Channel4 2.7 3.5
Channel5 0.2 1.3
Channel5 2.6 4.3
EOD

myY(col) = int(strcol(col)[strlen("Channel")+1:])

set style fill solid 1.0
boxwidth = 0.5
set offsets 0.1,0.2,0.5,0.5
plot $Data u (($2+$3)/2.):(myY(1)):(($3-$2)/2.):(boxwidth/2.):yticlabels(1) \
       w boxxyerrorbars lc rgb "web-green" notitle

### end of code

Result:

enter image description here

Upvotes: 1

Related Questions