我必须在同一张图上绘制几条曲线。我必须使用 for 循环来做到这一点。我想用线绘制前两条曲线,用点绘制其他曲线。我可以用线绘制所有曲线或用点绘制所有曲线,但不能在同一个 for 循环中进行更改。
这是我的代码的相关部分:
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"
plot for [i=1:words(FILES)] myDataFile(i) u (column(1)):((word(UTAUS_ch,i))) ls i title myTitle(i)
我想写序言“ls i" with "w l“对于前 2 条曲线和”ls i“对于其他人。我尝试通过替换”来使用 if 语句ls i" by "if (i " 但 Gnuplot 不希望在此位置找到 if 语句。
有人能帮我吗 ?
谢谢你,
马丁
如上所述here您可能无法在一个plot for
环形。
所以,要么你做两个单独的循环,一个with points
和另一个with lines
或者你做一个循环with linespoints
并将点和线的所有必要参数定义为函数(以保持绘图命令的可读性)。
如上所述here, linewidth 0
不是零,而是可能的最细线,通常为 1 像素。要使该线完全消失,您必须使用linetype -2
.
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
Result:
添加:
为了使绘图命令尽可能简短和清晰,您还可以定义线条样式并在plot for
命令通过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)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)