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

JupyterViz: Easy way to plot multiple measures in 1 figure #1821

Closed
rht opened this issue Sep 26, 2023 · 5 comments · Fixed by #1941
Closed

JupyterViz: Easy way to plot multiple measures in 1 figure #1821

rht opened this issue Sep 26, 2023 · 5 comments · Fixed by #1941

Comments

@rht
Copy link
Contributor

rht commented Sep 26, 2023

What's the problem this feature will solve?
Currently, each agent variable can only be plotted in separate figures. The virus on a network example is one such use case where we want to plot everything in one figure. See projectmesa/mesa-examples#56 (comment).

Describe the solution you'd like

Supporting this could be as simple as detecting if measure in

def make_plot(model, measure):
is a list. If so, plot all of them in 1 figure.

@rht
Copy link
Contributor Author

rht commented Sep 26, 2023

If there is no objection to my proposed design, this would be quick for @ankitk50 to implement.

@ankitk50
Copy link
Contributor

Can you also give an example model where this can be tested?

@rht
Copy link
Contributor Author

rht commented Sep 26, 2023

This example already implements the feature: https://github.com/projectmesa/mesa-examples/tree/main/examples/virus_on_network. It just needs to be ported to core Mesa.

@rht
Copy link
Contributor Author

rht commented Oct 7, 2023

@ankitk50 this is very likely to be a quick merge, since the other 2 PRs are still in draft.

@EwoutH
Copy link
Member

EwoutH commented Oct 26, 2023

What's the current status of this effort?

@rht rht mentioned this issue Oct 30, 2023
rht added a commit to rht/mesa that referenced this issue Jan 7, 2024
Fixes projectmesa#1821.

This provides a declarative interface to plotting multiple lines in 1
chart.

Example usage for virus on network
```python
page = JupyterViz(
    VirusOnNetwork,
    model_params,
    measures=[
        # This is subject to change, as it could have been
        # {"Infected": {"color": "tab:red"}}, but let's keep it simple.
        {"Infected": "tab:red", "Susceptible": "tab:green", "Resistant": "tab:gray"},
        # Alternatively, if you don't want to manually specify colors:
        # ["Infected", "Susceptible", "Resistant"],
        make_text(get_resistant_susceptible_ratio),
    ],
    name="Virus Model",
    agent_portrayal=agent_portrayal,
```
rht added a commit to rht/mesa that referenced this issue Jan 7, 2024
Fixes projectmesa#1821.

This provides a declarative interface to plotting multiple lines in 1
chart.

Example usage for virus on network
```python
page = JupyterViz(
    VirusOnNetwork,
    model_params,
    measures=[
        # This is subject to change, as it could have been
        # {"Infected": {"color": "tab:red"}}, but let's keep it simple.
        {"Infected": "tab:red", "Susceptible": "tab:green", "Resistant": "tab:gray"},
        # Alternatively, if you don't want to manually specify colors:
        # ["Infected", "Susceptible", "Resistant"],
        make_text(get_resistant_susceptible_ratio),
    ],
    name="Virus Model",
    agent_portrayal=agent_portrayal,
```
rht added a commit to rht/mesa that referenced this issue Jan 7, 2024
Fixes projectmesa#1821.

This provides a declarative interface to plotting multiple lines in 1
chart.

Example usage for virus on network
```python
page = JupyterViz(
    VirusOnNetwork,
    model_params,
    measures=[
        # This is subject to change, as it could have been
        # {"Infected": {"color": "tab:red"}}, but let's keep it simple.
        {"Infected": "tab:red", "Susceptible": "tab:green", "Resistant": "tab:gray"},
        # Alternatively, if you don't want to manually specify colors:
        # ["Infected", "Susceptible", "Resistant"],
        make_text(get_resistant_susceptible_ratio),
    ],
    name="Virus Model",
    agent_portrayal=agent_portrayal,
```
rht added a commit to rht/mesa that referenced this issue Jan 9, 2024
Fixes projectmesa#1821.

This provides a declarative interface to plotting multiple lines in 1
chart.

Example usage for virus on network
```python
page = JupyterViz(
    VirusOnNetwork,
    model_params,
    measures=[
        # This is subject to change, as it could have been
        # {"Infected": {"color": "tab:red"}}, but let's keep it simple.
        {"Infected": "tab:red", "Susceptible": "tab:green", "Resistant": "tab:gray"},
        # Alternatively, if you don't want to manually specify colors:
        # ["Infected", "Susceptible", "Resistant"],
        make_text(get_resistant_susceptible_ratio),
    ],
    name="Virus Model",
    agent_portrayal=agent_portrayal,
```
Corvince pushed a commit that referenced this issue Jan 9, 2024
Fixes #1821.

This provides a declarative interface to plotting multiple lines in 1
chart.

Example usage for virus on network
```python
page = JupyterViz(
    VirusOnNetwork,
    model_params,
    measures=[
        # This is subject to change, as it could have been
        # {"Infected": {"color": "tab:red"}}, but let's keep it simple.
        {"Infected": "tab:red", "Susceptible": "tab:green", "Resistant": "tab:gray"},
        # Alternatively, if you don't want to manually specify colors:
        # ["Infected", "Susceptible", "Resistant"],
        make_text(get_resistant_susceptible_ratio),
    ],
    name="Virus Model",
    agent_portrayal=agent_portrayal,
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants