如前所述,您可能无法在plot for
循环中切换绘图样式。所以,要么你做两个单独with points
的循环,一个和另一个with lines
,或者你做一个循环with linespoints
并将点和线的所有必要参数定义为函数(以保持绘图命令可读)。正如这里提到的,linewidth 0
不是零,而是最细的线,通常是 1 个像素。要使线条完全消失,您必须使用linetype -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
结果:
添加:
为了使绘图命令尽可能简短和清晰,您还可以定义线条样式并在plot for
命令中使用它 via ls i
,结果与上面相同。
...
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)