问题
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