Comments on: AgentsPlot https://helipad.dev Agent-based modeling in Python Fri, 16 Jun 2023 18:37:53 +0000 hourly 1 https://wordpress.org/?v=6.9.4 By: charwick https://helipad.dev/functions/agentsplot/#comment-600 Fri, 16 Jun 2023 18:37:53 +0000 https://helipad.dev/?page_id=596#comment-600 A single AgentsPlot object can support any or all of spatial, network, and scatterplot layouts, which can be rotated through with the L key. The network structure will be displayed over all layouts, including the spatial and scatterplots unless the value of plot.network does not correspond to a network name. This example makes all three layout types available.

import random
from helipad import Helipad
heli = Helipad()

@heli.hook
def modelPostSetup(model):
    model.agents.createNetwork(0.2, 'connections')

@heli.hook
def agentInit(agent, model):
    agent.p1 = random.uniform(0,100)
    agent.p2 = random.uniform(0,200)

#This function returns `AgentsPlot` and sets the default layout to `spatial`.
#We get the object this way rather than with `heli.visual.addPlot(type='agents')`
#because the latter will not make a spatial layout available.
plot = heli.spatial()

plot.network = 'connections'
plot.scatter = ('p1', 'p2')
]]>
By: charwick https://helipad.dev/functions/agentsplot/#comment-109 Sat, 12 Jun 2021 17:15:53 +0000 https://helipad.dev/?page_id=596#comment-109 More complex rules for the 'agentSize' parameter, or for scatterplotting, can be used by creating properties. This example sets the size of the firms in a multi-level model to be the population of agents within that firm.

from helipad import Helipad, MultiLevel, Agent
heli = Helipad()

heli.primitives.add('firm', MultiLevel, dflt=20, priority=1)
heli.removePrimitive('agent')
mapPlot = heli.spatial(x=5, y=1, wrap=False)

#Add a .size property to the firms, which can be used for the agentSize parameter
def firmsize(self): return len(self.agents['agent'])
MultiLevel.size = property(firmsize)
mapPlot.config('agentSize', 'size')
]]>