plot turtles vs energy

老子叫甜甜 提交于 2019-12-12 21:04:17

问题


Hello netlogo community

I have a simple model with 100 turtles and each one has a variable called energy. How can I draw a graph that plots for each turtle in the world his energy I mean: x-axis each turtle y-axis energy associated to the turtle

Sorry I think is an easy question but I can figure out how to do it. Ideally I would like an histogram like the following:

Histogram


回答1:


The NetLogo histogram command won't allow you to plot each value individually, but it's not too hard to code it yourself.

Supposing you have a model with the following code:

turtles-own [ energy ]
to setup
  clear-all
  create-turtles 100 [ set energy random 100 ]
  reset-ticks
end

You can add a plot with a pen that is defined like this:

(Don't forget to set the pen mode to "Bar"!)

To get a plot like this:

Note that this uses the new NetLogo 6.0 anonymous procedure syntax. In NetLogo <= 5.3.1, you'd use [ ask ? [ plot energy ] ] instead of [ [t] -> ask t [ plot energy ] ].

Also note that sort will sort your turtles by who number. Use sort-on if you prefer a different order.



来源:https://stackoverflow.com/questions/41594792/plot-turtles-vs-energy

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