2

下图是用 gnuplot 生成的:在此处输入图像描述

它显示了 5 个(但可能或多或少)波。但是,我需要的是分别显示每个波浪,就像这样(我用 gimp 做的):

在此处输入图像描述

有没有办法用 gnuplot 做到这一点?我还需要每个波浪都是不同的颜色,就像我现在一样。

这是使用的 gnuplot 脚本:http: //pastebin.com/vAD2syTS

这是 gnuplot 脚本用来修复我的数据的 python 脚本:http: //pastebin.com/WEncNjDA

这是数据: http: //pastebin.com/ewBpvHWM

这是python脚本修复后的数据:http: //pastebin.com/cgimMyr9

4

2 回答 2

6

这个我玩得很开心。我的策略包括绘制设置略有不同的第一个、最后一个和中间图,以使边界对齐。我还定义了一些函数,以确保所有绘图颜色确实不同,除非您有超过 1600 万个数据集要绘制。

### indices: change this parameter to equal the number of data sets to be plotted
indices = 8 
# h: height of output in pixels
h = 150.0*indices
# d: top and bottom margin in pixels
d = 75.0

### define functions to help set top/bottom margins
top(i,n,h,d) = 1.0 - (d+(h-2*d)*(i-1)/n)/h
bot(i,n,h,d) = 1.0 - (d+(h-2*d)*i/n)/h

### define some fun RGB code converter functions

# round: crude rounding function (gnuplot doesn't have this?)
# assumes a float, returns an int
round(x) = x-int(x)>=0.5?ceil(x):floor(x)

# i2h: converts a (decimal) integer between 0 and 15 to hex.
# returns a string, 0-F corresponding to 0-15
i2h(i) = i==10?'A':i==11?'B':i==12?'C':i==13?'D':i==14?'E':i==15?'F':sprintf('%d',i)

# i2r: converts an integer to an RGB code.
# returns a string (RGB code) of length 6, 000000-FFFFFF corresponding to 0-16777215
# changing the last division to 15 instead of 16 prevents colors being too faint
i2r5(i) = i2h(i/(15**5))
i2r4(i) = i2h(i%(16**5)/(15**4))
i2r3(i) = i2h(i%(16**5)%(16**4)/(15**3))
i2r2(i) = i2h(i%(16**5)%(16**4)%(16**3)/(15**2))
i2r1(i) = i2h(i%(16**5)%(16**4)%(16**3)%(16**2)/(15**1))
i2r0(i) = i2h(i%(16**5)%(16**4)%(16**3)%(16**2)%(16**1))
i2r(i) = i2r5(i).i2r4(i).i2r3(i).i2r2(i).i2r1(i).i2r0(i)

# rgb_iter: returns the i-th of n RGB codes, evenly spaced across the spectrum
rgb_iter(i, n) = '#'.i2r(round((i-1)*(16777215.0/(n-1))))

### first set up some basic plot parameters
set term png enhanced size 800,h font 'Courier-Bold,14'
set output 'waves.png'

set title 'Wave propagation by geophones'
set ylabel 'Wave'

set xrange [1400:]
set yrange [-0.15:0.15]
set ytics ('-0.1' -0.1, '0.0' 0.0, '0.1' 0.1)

set key out right

### now make plots
set multiplot layout indices,1

### first plot
set border 14
set tmargin at screen top(1,indices,h,d)
set bmargin at screen bot(1,indices,h,d)
unset xtics
plot 'temp.dat' index 0 w lines lw 3 lc rgb rgb_iter(1,indices) title 'Geophone 1'
unset title

### intermediate plots
set border 10
unset xlabel
do for [i=1:indices-2] {
 set tmargin at screen top(i+1,indices,h,d)
 set bmargin at screen bot(i+1,indices,h,d)
 plot 'temp.dat' index i w lines lw 3 lc rgb rgb_iter(i+1,indices) title sprintf('Geophone %d', i + 1)
}

### last plot
set border 11
set tmargin at screen top(indices,indices,h,d)
set bmargin at screen bot(indices,indices,h,d)
set xtics nomirror
set xlabel 'Iterations'
plot 'temp.dat' index (indices-1) w lines lw 3 lc rgb rgb_iter(indices,indices) title sprintf('Geophone %d', indices)

unset multiplot

示例数据集的输出如下所示: 在此处输入图像描述

顶部/底部地块的大小不是很完美,正如 mgilson 所说,可能需要一些set xmargin at screen ...命令才能使所有地块大小相等。

(如果没有别的,那些 int->RGB 转换器对于专门的应用程序很方便;我也有从 RGB 代码到整数的函数。)

编辑:我更新了脚本,所以所有的地块都将具有相同的高度。

于 2012-12-12T23:33:03.167 回答
5

如果您提前知道地块的数量(gnuplot 4.6):

NUM_PLOTS = 6
set multiplot layout NUM_PLOTS,1
do for [i=1:NUM_PLOTS]{
   plot 'temp.dat' index i w lines lw 3 title sprintf('Geophone %d', i + 1)
}
unset multiplot

如果你真的想确保你的边界和轴对齐,你可以使用 , , 和 where 的组合set lmargin at screen ...andset rmargin at screen ...set tmargin at screen ...一些set bmargin at screen ...功能...i尽管NUM_PLOTS可能将lmarginand设置rmargin在某个恒定位置就足够了(gnuplot 应该如果您不需要共享轴,请注意从上到下对齐)。

set border 10如果您真的需要,将删除顶部和底部边界线,但这可能不是必需的。

我会推荐类似的东西:

NUM_PLOTS = 6
set multiplot layout NUM_PLOTS,1
set lmargin at screen 0.1
set rmargin at screen 0.9
do for [i=1:NUM_PLOTS]{
   plot 'temp.dat' index i w lines lw 3 title sprintf('Geophone %d', i + 1)
}
unset multiplot
于 2012-12-12T21:53:28.170 回答