Reputation: 131
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.
Upvotes: 3
Views: 6800
Reputation: 30508
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:
Upvotes: 2
Reputation: 17678
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.
Upvotes: 2