Using ChartModule with multiple series

Skip to first unread message

Joel Carneiro

Jan 1, 2021, 7:08:33 PMJan 1
to ProjectMesa
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 :
def cumulative_values(self):
     return a, b, c, d    #or  return [a,b,c,d]

inside model __init__
self.datacollector = DataCollector( model_reporters={"Cumulatices": cumulative_values})
ChartModule([{"Label": "a Agents",
                           "Color": "#ff0000"}, 
                          {"Label": "b Agents",
                              "Color": "#ff6699"}, 
                          {"Label": "c Agents",
                           "Color": "#33cc33"}, 
                          {"Label": "d Agents",
                           "Color": "black"}],

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

Jan 2, 2021, 2:06:47 PMJan 2
to ProjectMesa
Well, I found a solution :)
self.datacollector_cumulatives = DataCollector(
            {"a Agents": cumulative_values_a,
             "b Agents": cumulative_values_b,
             "c Agents": cumulative_values_c,
             "d Agents": cumulative_values_d,})  
chart_cumulatives = ChartModule([{"Label": "aAgents",
                           "Color": "#ff0000"},
                          {"Label": "bAgents",
                           "Color": "#ff6699"},
                          {"Label": "cAgents",
                           "Color": "black"},
                          {"Label": "dAgents",
                           "Color": "#33cc33"}

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