问题描述
我试图研究文档,但没有找到所需的答案.所以我在这里问:
I tried to look into docs, but I haven't found the answer that I needed. So I am asking here:
例如,我有15只海龟(此数字可能有所不同),我需要将它们的变量(例如Revenue)绘制到一个图中.我知道我可以绘制1个代理槽命令的变量
I have for example 15 turtles (this number can vary) and I need to draw their variable (for example Revenue) into one plot. I know I can plot variable of 1 agent trough command
plot [revenue] of turtle 0
但是我该如何绘制整个代理集?
But how can I plot the whole agentset?
我的第二个问题是,当我有乌龟0的命令图[revenue]时,netlogo给我一个错误,该错误是:OF预期的输入是乌龟代理集或乌龟,但没有提示(当我按设置按钮时).如何避免呢?
My second problem is when I have the command plot [revenue] of turtle 0, netlogo gives me an error which says: OF expected input to be a turtle agentset or turtle but got NOBODY instead(when i press setup button). How to avoid it?
谢谢Mestralx.
Thanks, Mestralx.
推荐答案
您可以使用create-temporary-plot-pen
快速制作所需数量的绘图笔.就您而言,每只乌龟一只.
You can use create-temporary-plot-pen
to make as many plot pens as you need, on the fly. In your case, one per turtle.
这是一个小代码示例.假设我有:
Here's a little code example. Suppose I have:
to setup
clear-all
reset-ticks
end
to go
if ticks < 10 [ create-turtles 1 ]
ask turtles [ fd 1 ]
tick
end
现在在我的绘图中,我删除默认笔,并将其放在绘图的绘图更新命令"中:
Now in my plot, I delete the default pen, and I put this in the plot's "Plot update commands":
ask turtles [
create-temporary-plot-pen (word who)
set-plot-pen-color color
plotxy xcor ticks
]
如果我运行它,我将得到:
If I run it I get:
这篇关于如何正确绘制变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!