Reputation: 9816
How can I plot an attribute of an agentset in netlogo, each with a different pen. Consider there are other types of agents also, and the who numbers of the agentset to be plotted are not all consecutive to distribution/creation at start.
Upvotes: 1
Views: 87
Reputation: 9620
I take it that your question is really, "how can I associate each agent in an agentset with a pen?" Let's call the agentset myset
.
If the agentset is static (no agents created or dying) during the simulation, then you can introduce global mylst
and set it once to list of agents: set mylst [self] of myset
. You can then associate the pens with members of the list anyway you want. (E.g., you could also make a list of pens so that an agent's index in mylst
and its pen's index in mypens
is the same.)
You could use table
and map each pen name to an agent. (I probably like this solution best.)
If these agents constitute a breed, you could give the breed a pen
attribute that you set to its pen
name. (The only reason I dislike this solution is that it meddles with the attributes of the agent purely for GUI purposes, which I try to avoid.)
EDIT:
Since you are creating and destroying your agents, but you want each to control its own pen, you have a somewhat weird situation that could lead to a lot of bookkeeping. I'm going to suggest solution 3: add a pen
attribute to your agents. Now each time you create an agent, include as part of its initialization the following:
set pen (word "pen" who)
set-current-plot "myplot"
create-temporary-plot-pen pen
plot attribute
Here "myplot"
is the name of the plot you are using for this, and attribute
is the name of the attribute your are plotting. Then each tick you can have each of these agents
set-current-plot "myplot"
set-current-plot-pen pen
plot attribute
If you want to distinguish agents by pen color, you will have to do a little extra work. (See the scale-color
command for clues.)
Upvotes: 2