How to use the mesa.visualization.modules.ChartModule function in Mesa

To help you get started, we’ve selected a few Mesa examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Corvince / mesa-geo / examples / GeoSchelling / server.py View on Github external
"""
    Portrayal Method for canvas
    """
    portrayal = dict()
    if agent.atype is None:
        portrayal["color"] = "Grey"
    elif agent.atype == 0:
        portrayal["color"] = "Red"
    else:
        portrayal["color"] = "Blue"
    return portrayal


happy_element = HappyElement()
map_element = MapModule(schelling_draw, [52, 12], 4, 500, 500)
happy_chart = ChartModule([{"Label": "happy", "Color": "Black"}])
server = ModularServer(
    SchellingModel, [map_element, happy_element, happy_chart], "Schelling", model_params
)
server.launch()
github projectmesa / mesa / examples / Schelling / SchellingModular.py View on Github external
'''
    Portrayal Method for canvas
    '''
    if agent is None:
        return
    portrayal = {"Shape": "circle", "r": 0.5, "Filled": "true", "Layer": 0}

    if agent.type == 0:
        portrayal["Color"] = "Red"
    else:
        portrayal["Color"] = "Blue"
    return portrayal

happy_element = HappyElement()
canvas_element = CanvasGrid(schelling_draw, 20, 20, 500, 500)
happy_chart = ChartModule([{"Label": "happy", "Color": "Black"}])
model_params = {"height": 20, "width": 20, "density": 0.8, 
                #"minority_pc": 0.2, 
                "minority_pc": UserParam("minority_pc", 0.2, 0, 1.0, 0.1), 
                "homophily": UserParam("homophily", 4, 1, 8, 1)}
server = ModularServer(SchellingModel,
                       [canvas_element, happy_element, happy_chart],
                       "Schelling", model_params)
server.launch()
github AB-CE / abce / example / boltzmann_wealth_model / start.py View on Github external
def main(x_size, y_size):
    """ This function sets up a canvas to graphically represent the model 'MoneyModel'
    and a chart, than it runs the server and runs the model in model.py in the browser """
    grid = CanvasGrid(agent_portrayal, x_size, y_size, 500, 500)

    chart = ChartModule([{"Label": "Gini",
                          "Color": "Black"}],
                        data_collector_name='datacollector')
    # the simulation uses a class DataCollector, that collects the data and
    # relays it from self.datacollector to the webpage

    server = ModularServer(MoneyModel,
                           [grid, chart],
                           "ABCE and MESA integrated",
                           x_size * y_size, x_size, y_size)
    server.port = 8534  # change this number if address is in use
    server.launch()
github AB-CE / abce / examples / mesa_example / start.py View on Github external
def main(x_size, y_size):
    """ This function sets up a canvas to graphically represent the model 'MoneyModel'
    and a chart, than it runs the server and runs the model in model.py in the browser """
    grid = CanvasGrid(agent_portrayal, x_size, y_size, 500, 500)

    chart = ChartModule([{"Label": "Gini",
                          "Color": "Black"}],
                        data_collector_name='datacollector')
    # the simulation uses a class DataCollector, that collects the data and
    # relays it from self.datacollector to the webpage

    server = ModularServer(MoneyModel,
                           [grid, chart],
                           "abcEconomics and MESA integrated",
                           x_size * y_size, x_size, y_size)
    server.port = 8534  # change this number if address is in use
    server.launch()
github projectmesa / mesa / examples / bank_reserves / bank_reserves / server.py View on Github external
# dictionary of user settable parameters - these map to the model __init__ parameters
model_params = {"init_people": UserSettableParameter("slider", "People", 25, 1, 200,
                                                    description="Initial Number of People"),
                "rich_threshold": UserSettableParameter("slider", "Rich Threshold", 10, 1, 20,
                                                   description="Upper End of Random Initial Wallet Amount"),
                "reserve_percent": UserSettableParameter("slider", "Reserves", 50, 1, 100,
                                                    description="Percent of deposits the bank has to hold in reserve")
                }

# set the portrayal function and size of the canvas for visualization
canvas_element = CanvasGrid(person_portrayal, 20, 20, 500, 500)

# map data to chart in the ChartModule
chart_element = ChartModule([{"Label": "Rich", "Color": RICH_COLOR},
                             {"Label": "Poor", "Color": POOR_COLOR},
                             {"Label": "Middle Class", "Color": MID_COLOR}])

# create instance of Mesa ModularServer
server = ModularServer(BankReserves, [canvas_element, chart_element],
                       "Bank Reserves Model",
                       model_params=model_params
                       )
github projectmesa / mesa / examples / boltzmann_wealth_model_network / wealth_model / server.py View on Github external
n['agent'][0].wealth),
                           }
                          for n_id, n in G.nodes(data=True)]

    portrayal['edges'] = [{'id': i,
                           'source': source,
                           'target': target,
                           'color': '#000000',
                           }
                          for i, (source, target, _) in enumerate(G.edges(data=True))]

    return portrayal


grid = NetworkModule(network_portrayal, 500, 500, library='sigma')
chart = ChartModule([
    {"Label": "Gini", "Color": "Black"}],
    data_collector_name='datacollector'
)

model_params = {
    "num_agents": UserSettableParameter('slider', "Number of agents", 7, 2, 10, 1,
                                        description="Choose how many agents to include in the model"),
    "num_nodes": UserSettableParameter('slider', "Number of nodes", 10, 3, 12, 1,
                                       description="Choose how many nodes to include in the model, with at "
                                                   "least the same number of agents")
}

server = ModularServer(MoneyModel, [grid, chart], "Money Model", model_params)
server.port = 8521
github projectmesa / mesa / examples / sugarscape_cg / sugarscape_cg / server.py View on Github external
elif type(agent) is Sugar:
        if agent.amount != 0:
            portrayal["Color"] = color_dic[agent.amount]
        else:
            portrayal["Color"] = "#D6F5D6"
        portrayal["Shape"] = "rect"
        portrayal["Filled"] = "true"
        portrayal["Layer"] = 0
        portrayal["w"] = 1
        portrayal["h"] = 1

    return portrayal


canvas_element = CanvasGrid(SsAgent_portrayal, 50, 50, 500, 500)
chart_element = ChartModule([{"Label": "SsAgent", "Color": "#AA0000"}])

server = ModularServer(SugarscapeCg, [canvas_element, chart_element],
                       "Sugarscape 2 Constant Growback")
# server.launch()
github aragonlabs / court-sim / court / server.py View on Github external
from mesa.visualization.UserParam import UserSettableParameter
#from mesa.visualization.modules import TextElement
from mesa.visualization.ModularVisualization import ModularServer
#from mesa.visualization.TextVisualization import TextData
#from mesa.visualization.TextVisualization import TextVisualization

from court.model import CourtModel

chart1 = ChartModule([
    {"Label": "successful", "Color": "#7bb36e"},{"Label": "failed", "Color": "#c66657"},{"Label": "total", "Color": "#56bfdf"}],
    data_collector_name='datacollector',
    canvas_height=300, canvas_width=300
)


chart2 = ChartModule([
    {"Label": "Gini", "Color": "#56bfdf"}],
    data_collector_name='datacollector',
    canvas_height=300, canvas_width=300
)

server = ModularServer(
    CourtModel,
    [chart1,chart2],
    name="CourtModel",
    model_params={
        "juror_count": UserSettableParameter('slider', "Number of jurors", 20, 10, 100, 1,
                               description="Choose how many Juror agents to include in the model"),
        "token_count": UserSettableParameter('slider', "Number of tokens", 40, 10, 400, 1,
                                   description="Choose how many tokens in supply, tokens are split evenly among jurors at initialization."),
        "threshold": UserSettableParameter('slider', "Belief Threshold", 1, 0.25, 5, 0.25,
                                   description="Agents must sample within this many standard deviations from the true value to be coherent"),