Skip to main content
Version: 🚧 Alpha 🚧

10. Charts

This 10th step illustrates how to define charts.

Formulation​

  • Addition of a new display to visualize:
    • One chart representing the evolution of the quantity of prey and predator agents over time.
    • Two histograms representing the energy distribution of the prey and predator agents.

Model Definition​

output​

GAMA can display various chart types:

  • Time series
  • Pie charts
  • Histograms

A chart is defined inside a display, alongside other output layers.

Definition of a chart:

chart "Chart name" kind: series {
[data]
}

The data to draw are defined inside the chart block as follow, using the data statement:

data data_legend value: data_value

The model adds a Population_information display that refreshes every five cycles. It contains one series chart for population counts and two histograms that group prey and predator energies into ranges:

  • "Species evolution" shows the prey and predator counts over time.

  • "Prey Energy Distribution" groups prey by energy intervals from 0 to 1.

  • "Predator Energy Distribution" groups predator energy by the same intervals.

To evaluate the value of the data of the two histogram, we use the operator list count condition that returns the number of elements of list for which the condition is true.

display Population_information refresh: every(5 #cycles) renderer: 2d {
chart "Species evolution" coordinates: #screen kind: series size: {1,0.5} position: {0, 0} {
data "number_of_preys" value: nb_preys color: #blue ;
data "number_of_predator" value: nb_predators color: #red ;
}
chart "Prey Energy Distribution" coordinates: #screen kind: histogram background: #lightgray size: {0.5,0.5} position: {0, 0.5} {
data "]0;0.25]" value: prey count (each.energy <= 0.25) color:#blue;
data "]0.25;0.5]" value: prey count ((each.energy > 0.25) and (each.energy <= 0.5)) color:#blue;
data "]0.5;0.75]" value: prey count ((each.energy > 0.5) and (each.energy <= 0.75)) color:#blue;
data "]0.75;1]" value: prey count (each.energy > 0.75) color:#blue;
}
chart "Predator Energy Distribution" coordinates: #screen kind: histogram background: #lightgray size: {0.5,0.5} position: {0.5, 0.5} {
data "]0;0.25]" value: predator count (each.energy <= 0.25) color: #red ;
data "]0.25;0.5]" value: predator count ((each.energy > 0.25) and (each.energy <= 0.5)) color: #red ;
data "]0.5;0.75]" value: predator count ((each.energy > 0.5) and (each.energy <= 0.75)) color: #red ;
data "]0.75;1]" value: predator count (each.energy > 0.75) color: #red;
}
}

Complete Model​

gama.library/models/Tutorials/Predator%20Prey%20Tutorial/models/Model%2010.gaml
loading...