How to properly plot variables

﹥>﹥吖頭↗ 提交于 2019-12-23 17:13:51

问题


I tried to look into docs, but I haven't found the answer that I needed. So I am asking here:

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?

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?

Thanks, Mestralx.


回答1:


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:




回答2:


For the error, do you have reset-ticks anywhere in your code? You need that to initialise plots. Generally you should place it at the end of the setup procedure. Also, the plot commands (if you are using them) should not be called by setup, but should be in the go procedure, because otherwise you will only get the initial values rather than plots over time.

If your turtle count varies, your best approach might be to plot key values like the minimum, mean, median or whatever. NetLogo recommended practice is to do this in the interface directly rather than in code. So, you could create a plot on the interface with, for example mean [revenue] of turtles as the plot code. You can also do a histogram if you want all the revenue values to be displayed but that won't give you a plot over time.



来源:https://stackoverflow.com/questions/31200826/how-to-properly-plot-variables

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!