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.
Related
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:
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
I have created a model using the Roth-Erev reinforcement learning algorithm so that every round agents select their action a from a set of actions A. The actions count how often they are played throughout the entire game.
I would now like to create a histogram that has the frequency on the y-axis and the actions on the x-axis. I would also like to label every action with its parameters, but I understand that is not possible.
Merely using histogram count [n-played] of actions would not plot every action individually. I think plotxy comes closest but isn't suitable for histograms. Is there any build in solution or do I have to visualize data outside of Netlogo?
You won't be able to label the columns, but you are not limited to the histogram command for producing bar plot. Each plot pen has a mode that can be "line", "bar" or "point". By using the "bar" mode, you can produce bar plots with the plot or plotxy commands:
Here is the code for easy cut and paste:
plot-pen-reset
foreach map [ [ n-played ] of ? ] sort actions plot
Note that this uses the "concise task syntax" for passing plot to foreach. You can write [ plot ? ] if you prefer.
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.
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 ,