GEOG3150 - GIS, Geocomputation and Geoplanning - Semster 2


Table of Contents

1. Advanced Variables
2. Grass Grows...
3. Giving Birth.
4. Creating a graph.

Practical 3, part 4 - Creating a Graph


A graph

In the very last part of this practical, you will create a graph that shows the number of turtles alive on the y axis and the number of model iterations on the x axis. This is explained in detail in the NetLogo tutorial (see the Plotting section). Most of the material here has come from that tutorial.

  1. If you have closed it, re-open your sheep model.
  2. Then go to the Interface tab and create a new 'Plot' in the same way that you would create a button, slider, etc.
  3. Enter the following values to configure how the axes are displayed:
    Name:Total Number of Alive Turtles
    X axis labeltime
    Y axis labelcount
    Auto scale:✓ (This makes the axes grow over time)
  4. Next, we need to tell NetLogo how to draw the graph. To do this, it uses something called 'Plot Pens'. It is possible to have multiple pens per graph to draw a number of different things simultaneously. For this practical, we will create a single 'pen' that draws the number of turtles who are alive at a given time.

  5. Click on 'Add pen' to make a new pen
  6. Give the pen the name turtles-alive and choose a colour for the pen (this will determine the colour of the line on the chart). In the right figure I chose orange, but the colour doesn't matter.
  7. Plot pen
  8. The 'Plot Update Commands' section is where we tell NetLogo what we actually want the chart to plot. In there, type: plot count turtles This will plot the number of turtles currently in the model.
  9. Now the graph is ready. Click on OK and you should see an empty graph.
  10. Try running the model, sadly nothing will be drawn on the graph. To make the graph work there are two very small changes that we need to make to the model.

  11. Go into the Code tab.
  12. In the setup procedure, add the following code just before creating the patches and the turtles: __clear-all-and-reset-ticks What this strange command does is remove everything from the model and reset the 'tick counter' to zero. This will be run each time you click on the 'setup' button. If we don't do this, then the graph never goes back to zero, even after the model has been reset.
    Your setup procedure should now look something like this: to setup
     print "Setting up model."
     __clear-all-and-reset-ticks
     setup-patches
     setup-turtles
    end
  13. Lastly, find the go procedure. At the very end, just before the end command (that tells NetLogo we have finished with the go procedure add the single command: tick This makes NetLogo increment it's internal clock so we know how many iterations have passed since the model began running. The plot needs to know this.

That's it! Now go back to the Interface tab and try to run the model. Does the graph work? Experiment with the grass-regrow-time slider again. Does the graph make it easier to see what affect the slider has on the size of the turtle population?

That's everything for Practical 3. You now have a reasonably advanced model with animals that eat grass, give birth, and die. To finish off, have a go at the activities below.

Activities

  1. Add a plot pen that will show the number of green patches on the graph. If you get stuck, refer to the 'Plotting' section of the NetLogo tutorial.
  2. NetLogo has lots of different items that can provide information about a model. We have seen how graphs work; other items include monitors to display numbers (e.g. counts of things) and labels to show information about individual turtles or patches. The NetLogo tutorial has details about how to create these elements.

  3. Create two monitors: one to show how many turtles there are in the model and another to show how many patches are green. Hint: you can do this without adding anything to the 'Code' tab. Refer to the tutorial if you get stuck.
Example of using monitors

[School of Geography homepage] [Leeds University homepage]