Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Title "Undefined" when creating a linechart with mesa.visualization.modules.ChartModules #64

Closed
Sabi89129 opened this issue Oct 14, 2023 · 3 comments · Fixed by projectmesa/mesa-viz-tornado#37

Comments

@Sabi89129
Copy link

I used the following code for creating a line chart with mesa.visualization.modules.ChartModules.
Unfortunately the color is very weak and the tilte is shown as "Undefined".

image

class DiseaseModel(Model):
.
 def __init__(self,...):
      # Add datacollector for linechart
      self.datacollector = DataCollector(
      model_reporters={"Infected": get_num_infected_agents})

.
.
  def step(self):
        self.schedule.step()
        self.datacollector.collect(self)

infected_chart = visualization.ChartModule([{"Label":"Infected","Color":RED_COLOR}])
server = visualization.ModularServer(DiseaseModel, [grid,infected_chart],....)
@rht
Copy link
Contributor

rht commented Oct 15, 2023

Thank you for reporting. I confirm this is a bug in the frontend, where the "Label" actually has to be lower case "label" in order for the label to show up. According to https://www.chartjs.org/docs/3.6.2/charts/line.html, it has to be lower case. But currently in the code, it is hardcoded to expect "Label": https://github.com/projectmesa/mesa-viz-tornado/blob/77c80052d471cc4c830192b5a63824b8c79d69ea/mesa_viz_tornado/modules/ChartVisualization.py#L79.

This should be a quick fix.

@rht
Copy link
Contributor

rht commented Oct 15, 2023

As with the weak color, it's because the opacity is hardcoded to 0.1: https://github.com/projectmesa/mesa-viz-tornado/blob/77c80052d471cc4c830192b5a63824b8c79d69ea/mesa_viz_tornado/templates/js/ChartModule.js#L23.

Anyway, I recommend using the new pure Python frontend in mesa.experimental instead, which is based on Matplotlib, and allows you to avoid this problem altogether. See the app.py in https://github.com/projectmesa/mesa-examples/tree/main/examples/schelling_experimental.

@rht
Copy link
Contributor

rht commented Oct 15, 2023

With mesa.experimental.JupyterViz, you can only plot 1 line per plot. If you want multiple lines in 1 plot, see https://github.com/projectmesa/mesa-examples/blob/main/examples/virus_on_network/app.py instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants