Netlogo: plot update without adding new X axis values - netlogo

So I'm doing a program where agents have a certain life value and I want to make a plot about it.
In the X axis is the ID of the agent.
In the Y axis is the life of the agent.
The problem I have is that in every tick of execution it creates a new X axis value and I only want to update Y values without adding X.
How can I do that?

While you should definitely check out Alan's suggestion, you can use plotxy to do what you're asking:
ask turtles [
plotxy id life
]
where id and life are the variables you want to use for x and y. That is, if you're just using who numbers as for your ids, you'd do plotxy who life. But yeah, do checkout Alan's suggestion.

Related

Dynamically replotting every tick

I'm trying to plot two turtle variables against each other in a scatterplot. I want this plot to update continuously, and erase the points from previous steps. I.e. I want one point to move to represent the variable values for one turtle throughout its lifetime, disappearing when it dies and these values equal zero.
This is my code for the pen update commands (isspecials is my turtle agentset)
ask isspecials [plotxy r invader-stride]
I tried adding
reset-plot-pens
to the end of it, but then nothing appears on the plot. I think it's almost as if I have to create a new pen for each turtle, but I can't tell. I'm really new to this, so if anyone has any suggestions I'd really appreciate it!
I tried adding
reset-plot-pens
to the end of it
Adding plot-pen-reset is the right idea! However, you need to add it before your plotting command.
The plot-pen-reset primitive erases everything that the plot pen has drawn. If you call it right after you plot, you don't get a change to see anything! Calling it just before plotting new stuff will ensure that the stuff you plotted in the previous tick has plenty of time to be seen.
Here is what you plot pen definition should look like:

How to plot agent variables in NetLogo

I'm working through a textbook, and trying to plot the way a variable 'energy' changes over time, for two breeds, 'sheep' and 'wolves'.
When I try and plot the energy for wolves, I use the code:
plot [energy] of wolves
in the 'pen update commands' for my plot. When I try to run the model using the go procedure, I get the following error message:
PLOT expected input to be a number but got the list [105.09999999999982 129.59999999999982 112.09999999999982 112.09999999999982 112.09999999999982 108.59999999999982 129.59999999999982 115.59999999999982 108.59999999999982 119.09999999999982] instead.
error while observer running PLOT
called by plot 'Energy over Time' pen 'wolves' update code
called by procedure GO
called by Button 'go'
I'd appreciate it if anyone could tell me what I'm doing wrong, and how to get the plot to model the way the agents own variables change over time.
If you have 5 wolves, then you are asking NetLogo to plot a list of 5 numbers, but it needs a single number to plot (on y axis, and tick/time goes on x axis). You probably want the average energy of wolves. Try plot mean [energy] of wolves

Plotting variables of multiple agents

I am trying to plot a graph that shows the variables of all agents of one breed. Although the number of agents is rather small, I think there must be a more elegant way than creating a pen for every agent. Is there?
Elegance, here, depends on what exactly you want to do. It can be perfectly legitimate to create one plot pen per turtle, using create-temporary-plot-pen. Among advantages, it means that you can give each plot pen a name and show a legend on your plot.
That being said, it's also very easy to use a single pen for all your agents. Suppose you have multiple turtles, of different colors, and you want to plot their sizes. You can put something like this in a pen's "update commands":
ask turtles [ set-plot-pen-color color plotxy ticks size ]
This will change the pen to the color of each turtle and plot a single point for that turtle. Just be sure to set your pen to "point" mode in the advanced pen options.
Also notice the use of plotxy instead of just plot, allowing you to specify an x coordinate instead of relying on the "auto advance" behavior of plot.

Update some plots in NetLogo

Is it possible to have plots that are updated at different time points?
My model looks like that (it is replicator dynamics):
to go
repeat 10 [do-something]
replicate
tick
end
Then I would like to have one plot that is updated on tick, just like usual, and the second one that is updated at do-something and then reset at tick.
I tried to find a solution in documentation but update-plots command updates ALL plots which is not what i want.
You can use the various manual plotting commands (eg plotxy, plot-pen-down, plot-pen-up) to explicitly plot things, see the plotting section of the user manual, but is often simpler to have the plot commands in the plot rather than the code.
To do it in the plot instead of code, you could change to a structure like this (if your full code is suitable):
to go
do-something
if ticks mod 10 = 0 [ replicate ]
tick
end
and use the automatic update of plots with tick. You would also use the if ticks mod 10 = 0 trick in the update section of your plot.

Netlogo how does time relate to ticks?

I noticed that my tick counter does not show the same as the time in my plots. It seems 1 tick is roughly equal to 2 units of time on my graphs.
I would have thought that the time in plots was related to ticks, but this doesnt seem to be the case.
How does these two relate?
If you want absolute control over both coordinates of the points you are plotting, use plotxy instead of plot.
If you just use plot, then the x coordinate just ends up being "how many times I've called plot". If you always call plot exactly once per tick, that will equal the number of ticks.
Perhaps you are, without realizing it, calling plot either more or less frequently than that...? Note that it's possible (and recommended) to have all of your plotting code inside plots, but you might also (or instead) have plotting code in the Code tab.
If you can tell us more about how you define your time unit in your graph we might be able to help you more, but as far as I know a tick 's length is all dependent on computation and its the time taken to iterate through your Go (or whenever you defined tick from start to end once! )
But you can use timer for measuring time taken after resetting timer in milliseconds :
http://ccl.northwestern.edu/netlogo/docs/dict/timer.html
In your problem, I think it's better to check interval in your plot, if it's anything other than 1 it means it does not update your plot every tick ,