1

I can plot the sum of worms per animal using the code below (visualized in Figure 1).

plot sum [worm-number] of animals

Figure 1. Graph showing sum of worms per animal with a Netlogo Monitor Figure 1.

I want my graph to be cumulative however like Figure 2 but I don't know how to code this. Previous examples use older syntax which does not work in NetLogo 6.2.0 and does not show how to plot the data.

Figure 2. Example of a cumulative graph which is required (I only need to plot 1 variable). Figure 2.

1 Answers1

3

You only have to use a global variable which will keep track of the new worms, and to which you will refer for plotting.

As we do not have a full example of your code, I am just going to write something that plausibly mimics what you should do:

breed [animals animal]

globals [
 cumulative-worms
]

; **************************
; The rest of your code here
; **************************

to get-infected   ; The procedure executed by animals when they get new worms.
 let new-worms (1 + random 5)
 set worm-number (worm-number + new-worms)
 set cumulative-worms (cumulative-worms + new-worms)
end

At this point you can just create a plot where you will use plot cumulative-worms.

Matteo
  • 2,774
  • 1
  • 6
  • 22