Using ChartModule with multiple series

5 views
Skip to first unread message

Joel Carneiro

unread,
Jan 1, 2021, 7:08:33 PMJan 1
to ProjectMesa
Hello,
I am using mesa to build a simple simulation. 
I have a simulation and a case where I want to show the number of agents with the health status a,b,c and d, in each step. I want all data in one chart. 

For now, I have 4 datacollector instances and 4 charts as I cannot put all together.

My problem is how to connect the mode_reporters with the series in the ChartModule class as I am trying to have one reporter pointing to a function that returns a pack or maybe a list with the values I want.

example code :

model.py
def cumulative_values(self):
    some_conditions....
    
     return a, b, c, d    #or  return [a,b,c,d]


inside model __init__
self.datacollector = DataCollector( model_reporters={"Cumulatices": cumulative_values})

visualization_model.py
ChartModule([{"Label": "a Agents",
                           "Color": "#ff0000"}, 
                          {"Label": "b Agents",
                              "Color": "#ff6699"}, 
                          {"Label": "c Agents",
                           "Color": "#33cc33"}, 
                          {"Label": "d Agents",
                           "Color": "black"}],
                         data_collector_name='datacollector')

I am not understanding how to use the datacollector object with the ChartModel. The documentation/tutorial is not too deep in this matter.

Thanks in advance!

Joel Carneiro

unread,
Jan 2, 2021, 2:06:47 PMJan 2
to ProjectMesa
Well, I found a solution :)

model.py
self.datacollector_cumulatives = DataCollector(
            {"a Agents": cumulative_values_a,
             "b Agents": cumulative_values_b,
             "c Agents": cumulative_values_c,
             "d Agents": cumulative_values_d,})

visualization_model.py  
chart_cumulatives = ChartModule([{"Label": "aAgents",
                           "Color": "#ff0000"},
                          {"Label": "bAgents",
                           "Color": "#ff6699"},
                          {"Label": "cAgents",
                           "Color": "black"},
                          {"Label": "dAgents",
                           "Color": "#33cc33"}
                          ],
                         data_collector_name='datacollector_cumulatives')

each  cumulative_values_(value) is a function returning an integer
Reply all
Reply to author
Forward
0 new messages