tom*_*sen 26 arrays loops for-loop gnuplot
这个问题与gnuplot内部的循环结构有关吗?而答案也由DarioP.
gnuplot 4.6引入了do命令.我如何使用它来循环一个例如文件和颜色的数组?什么是正确的语法?
colors = "red green #0000FF"
files = "file1 file2 file3"
do for [i=1:3] {
plot files(i).".dat" lc colors(i)
}
Run Code Online (Sandbox Code Playgroud)
Chr*_*oph 41
如果要将所有文件放在一个图中,则需要使用plot for[...(从4.4版开始支持).循环使用多个plot命令do for(仅从4.6版开始支持)仅在multiplot模式下工作.
以下两种解决方案都在一个图中绘制所有数据,但在迭代中略有不同.
第一种解决方案用于word在绘图时直接从字符串中提取单词.
colors = "red green #0000FF"
files = "file1 file2 file3"
plot for [i=1:words(files)] word(files, i).'.dat' lc rgb word(colors, i)
Run Code Online (Sandbox Code Playgroud)
第二个解决方案更改linetype然后直接在单词列表上迭代而不是使用索引.
colors = "red green #0000FF"
files = "file1 file2 file3"
set for [i=1:words(colors)] linetype i lc rgb word(colors, i)
plot for [file in files] file.'.dat'
Run Code Online (Sandbox Code Playgroud)