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

Boid flockers: Add Solara viz file #81

Merged
merged 1 commit into from
Jan 21, 2024
Merged

Conversation

rht
Copy link
Contributor

@rht rht commented Jan 9, 2024

No description provided.

@rht rht force-pushed the boid_solara branch 2 times, most recently from ad3cad3 to ddf1858 Compare January 21, 2024 22:33
@EwoutH
Copy link
Member

EwoutH commented Jan 21, 2024

Could you add a screenshot how it looks?

@rht
Copy link
Contributor Author

rht commented Jan 21, 2024

2024-01-21T17:40:08,565713518-05:00

@EwoutH
Copy link
Member

EwoutH commented Jan 21, 2024

Thanks, better than nothing, but some sense of direction and following might be useful.

I remember doing this for an exam, let me check if I still have code for this.

@EwoutH
Copy link
Member

EwoutH commented Jan 21, 2024

Found it, but it was a custom matplotlib function. It would be nice to have an arrow-like shape to know the direction, and either random colors or to let them take the colors of a group/leader.

Screenshot_351

# set the colormap we will use for plotting
bwr = plt.get_cmap("gist_rainbow")

def draw_boids(model):
    x_vals = []
    y_vals = []
    u_vals = []
    v_vals = []
    colors = []  # List to hold the color for each agent

    # Generate unique colors with saturation and transparency
    # Use a colormap with high saturation, such as "hsv"
    cmap = plt.get_cmap("hsv")
    n_agents = len(model.schedule.agents)
    color_indices = np.linspace(0, 1, n_agents)

    for i, boid in enumerate(model.schedule.agents):
        x, y = boid.pos
        u, v = boid.direction_vector
        x_vals.append(x)
        y_vals.append(y)
        u_vals.append(u)
        v_vals.append(v)
        
        # Assign a color with transparency; alpha value less than 1 introduces transparency
        colors.append(cmap(color_indices[i])[:3] + (0.6,))  # Change 0.6 to the desired transparency

    fig = plt.figure(figsize=(7, 7))
    ax = fig.add_subplot(111)

    # Use quiver with colors
    q = ax.quiver(x_vals, y_vals, u_vals, v_vals, color=colors, angles='xy', pivot='mid',
                  headaxislength=8, headlength=10, headwidth=7, scale=35)

    # The call to `embed_identity` is not changed.
    embed_identity(ax, student_name, student_number)

draw_boids(model)

@rht
Copy link
Contributor Author

rht commented Jan 21, 2024

It definitely is more informative.

However, this PR is limited in its scope to get a feature parity of the JupyterViz with the Tornado viz. I can add the directions in a separate PR.

@rht
Copy link
Contributor Author

rht commented Jan 21, 2024

You should raise an issue for it in projectmesa/mesa so that I don't forget to add the arrow and hue to the JupyterViz continuous space.

@EwoutH
Copy link
Member

EwoutH commented Jan 21, 2024

Done:

Go ahead and merge this one if you like.

@rht rht merged commit e28db2d into projectmesa:main Jan 21, 2024
2 checks passed
@rht rht deleted the boid_solara branch January 21, 2024 23:03
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 this pull request may close these issues.

2 participants