For loop gnuplot:在for循环中设置线条样式
我必须在同一张图上画几条曲线。我需要使用for循环来实现这一点。我想用直线绘制前两条曲线,用点绘制其他曲线。我能够绘制所有带线的曲线或所有带点的曲线,但不能在相同的for循环中更改。 以下是我的代码的相关部分:For loop gnuplot:在for循环中设置线条样式,for-loop,gnuplot,linestyle,For Loop,Gnuplot,Linestyle,我必须在同一张图上画几条曲线。我需要使用for循环来实现这一点。我想用直线绘制前两条曲线,用点绘制其他曲线。我能够绘制所有带线的曲线或所有带点的曲线,但不能在相同的for循环中更改。 以下是我的代码的相关部分: 将样式行1 lw 1 lc rgb设置为“绿色” 设置样式行2 lw 1 lc rgb“紫色” 设置样式行3 pt 1 ps 1.0 lc rgb“红色” 设置样式行4 pt 2 ps 1.0 lc rgb“红色” 设置样式行5 pt 3 ps 1.0 lc rgb“红色” [i=1:w
将样式行1 lw 1 lc rgb设置为“绿色”
设置样式行2 lw 1 lc rgb“紫色”
设置样式行3 pt 1 ps 1.0 lc rgb“红色”
设置样式行4 pt 2 ps 1.0 lc rgb“红色”
设置样式行5 pt 3 ps 1.0 lc rgb“红色”
[i=1:words(FILES)]myDataFile(i)u(第(1)列)的绘图:((word(UTAUS_ch,i)))ls i title myTitle(i) 我想在“ls I”之前为前两条曲线加上“w l”,为其他曲线加上“ls I”。我试图使用if语句,将“ls I”替换为“if(I<2){w l ls I}else{ls I}”,但Gnuplot不希望在这个位置找到if语句 有人能帮我吗? 非常感谢。 Martin如前所述,您可能无法在
循环的打印中切换打印样式。
因此,您可以执行两个单独的循环,一个带点
,另一个带线
,或者执行一个带线点
的循环,并将点和线的所有必要参数定义为函数(以保持绘图命令的可读性)。
如前所述,线宽0
不是零,而是最细的线,通常为1像素。要使线条完全消失,必须使用线型-2
代码:
### lines and points in the same plot for-loop
reset session
LINECOLORS = "red green blue magenta cyan"
LINEWIDTHS = '1.0 4.0 0.0 0.0 0.0'
POINTTYPES = '0 0 5 7 9'
POINTSIZES = '0 0 1.0 2.0 3.0'
TITLES = 'one two three four five'
myLinecolor(i) = word(LINECOLORS,i)
myLinewidth(i) = real(word(LINEWIDTHS,i))
myPointtype(i) = int(word(POINTTYPES,i))
myPointsize(i) = real(word(POINTSIZES,i))
myLinetype(i) = myLinewidth(i) == 0 ? -2 : 1
myTitle(i) = word(TITLES,i)
set samples 31
set key out
plot for [i=1:words(TITLES)] (sin(0.25*x-i)) w lp pt myPointtype(i) ps myPointsize(i) \
lt myLinetype(i) lw myLinewidth(i) lc rgb myLinecolor(i) title myTitle(i)
### end of code
结果:
### lines and points in the same plot for-loop
reset session
LINECOLORS = "red green blue magenta cyan"
LINEWIDTHS = '1.0 4.0 0.0 0.0 0.0'
POINTTYPES = '0 0 5 7 9'
POINTSIZES = '0 0 1.0 2.0 3.0'
TITLES = 'one two three four five'
myLinecolor(i) = word(LINECOLORS,i)
myLinewidth(i) = real(word(LINEWIDTHS,i))
myPointtype(i) = int(word(POINTTYPES,i))
myPointsize(i) = real(word(POINTSIZES,i))
myLinetype(i) = myLinewidth(i) == 0 ? -2 : 1
myTitle(i) = word(TITLES,i)
set samples 31
set key out
plot for [i=1:words(TITLES)] (sin(0.25*x-i)) w lp pt myPointtype(i) ps myPointsize(i) \
lt myLinetype(i) lw myLinewidth(i) lc rgb myLinecolor(i) title myTitle(i)
### end of code
添加:
### lines and points in the same plot for-loop
reset session
LINECOLORS = "red green blue magenta cyan"
LINEWIDTHS = '1.0 4.0 0.0 0.0 0.0'
POINTTYPES = '0 0 5 7 9'
POINTSIZES = '0 0 1.0 2.0 3.0'
TITLES = 'one two three four five'
myLinecolor(i) = word(LINECOLORS,i)
myLinewidth(i) = real(word(LINEWIDTHS,i))
myPointtype(i) = int(word(POINTTYPES,i))
myPointsize(i) = real(word(POINTSIZES,i))
myLinetype(i) = myLinewidth(i) == 0 ? -2 : 1
myTitle(i) = word(TITLES,i)
set samples 31
set key out
plot for [i=1:words(TITLES)] (sin(0.25*x-i)) w lp pt myPointtype(i) ps myPointsize(i) \
lt myLinetype(i) lw myLinewidth(i) lc rgb myLinecolor(i) title myTitle(i)
### end of code
为了使plot命令尽可能简短和清晰,您还可以定义线型,并通过ls i
在plot for
命令中使用它,结果与上述相同
...
do for [i=1:words(TITLES)] {
set style line i pt myPointtype(i) ps myPointsize(i) \
lt myLinetype(i) lw myLinewidth(i) lc rgb myLinecolor(i)
}
plot for [i=1:words(TITLES)] (sin(0.25*x-i)) w lp ls i title myTitle(i)
这里有一种使用宏的方法:
set style line 1 lw 1 lc rgb "green"
set style line 2 lw 1 lc rgb "purple"
set style line 3 pt 1 ps 1.0 lc rgb "red"
set style line 4 pt 2 ps 1.0 lc rgb "red"
set style line 5 pt 3 ps 1.0 lc rgb "red"
set samp 100
set macro
cmd = ''
do for [i=1:10] {s = i<3? 'w l' : 'ls '.i;
cmd = cmd . '"+" us 1:(sin(x-'.i.'/10.)) '.s.' title "key '.i.'",'}
plot [0:2*pi] @cmd
将样式行1 lw 1 lc rgb设置为“绿色”
设置样式行2 lw 1 lc rgb“紫色”
将样式行3 pt 1 ps 1.0 lc rgb设置为“红色”
将样式行4 pt 2 ps 1.0 lc rgb设置为“红色”
设置样式行5 pt 3 ps 1.0 lc rgb“红色”
设置samp 100
设置宏
cmd=''
为[i=1:10]{s=i检查此项。。。