以相同的 Yrange 绘制数据

plot data at same Yrange

我有这个数据:

Channel1 3 5
Channel1 1 2
Channel2 1 3

我的目标是在同一条线上绘制 Channel1 的值,我试图从这个问题中获得灵感:Channel1 在 Y 上出现了 2 次-轴

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.):0:((-)/2.):(boxwidth/2.):yticlabels(1) w boxxyerrorbars notitle

如果您的关键字只是 Channel+<number>,您可以定义一个函数来提取此数字。 在下面的示例中,例如通道 3 缺失,因此会有间隙。 如果您的关键字是任意的,那么您必须构建一个唯一的关键字列表(类似于哈希-table 或字典)并分配数字。这在 gnuplot 中也是可能的,但更多 "complicated".

代码:

### 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.):(myY(1)):((-)/2.):(boxwidth/2.):yticlabels(1) \
       w boxxyerrorbars lc rgb "web-green" notitle

### end of code

结果: