【发布时间】:2020-12-13 11:43:10
【问题描述】:
在重新绘制的 3 个版本中,只有 2 个可以按需要工作:
plot sin(x)
replot sin(x)/2
replot sin(x)/3
replot sin(x)/4
在每个命令之后,相应的曲线将添加到绘图中 - 正如预期的那样。
plot sin(x)
replot for [i=2:4] sin(x)/i
给出相同的(最终)结果(图中有 4 条曲线),但是
plot sin(x)
do for [i=2:4] {replot sin(x)/i}
导致绘图只有第一条和第四条曲线,尽管键中写了 4 条线。这是一个“功能”还是(如何)我可以在 do-for-version 中获得 4 条曲线(因为我必须在 do-clause 中做一些额外的事情)?
[gnuplot 5.2 (8),Ubuntu MATE 20.04]
【问题讨论】:
-
您可以像这样
plot for [i=1:4] sin(x)/i绘制所有 4 条曲线。在为什么需要do for循环之间,您还需要做什么? -
除了一些其他的东西(使用'i'的计算)我想 - 说非常简化 - 还要画 cos(x)/i。使用 "replot for [i=2:4] sin(x)/i ; replot for [i=2:4] cos(x)/i" 会产生错误的顺序,因为我想要 sin(x), cos(x ), sin(x)/2, cos(x/2, ...
-
实际上在上一个示例中,
sin(x)/4的 3 条曲线将相互重叠。如果您在 gnuplot 控制台中输入show plot,您将获得last plot command was: plot sin(x), sin(x)/i, sin(x)/i, sin(x)/i和最后一个replot命令i=4。我想这就是replot的工作方式。它不会绘制sin(x), sin(x)/2, sin(x)/3, sin(x)/4。 -
如果订单很重要,例如对于交替的 sin(x)、cos(x) 示例,您可以使用:
plot for [i=1:4] for [b=0:1] b?sin(x)/i:cos(x)/i title sprintf("%s(x)/%d",b?'sin':'cos',i)。但也许您可以编辑问题并更详细地描述您的最终目标。 -
“我想这就是 replot 的工作方式。” - 看起来像,是的。所以我找到了一个创建宏的解决方案(我将在几秒钟内发布)。 (虽然这在我的实际问题中并不像这里的这个简单示例那样好。)