Using abmplot() for plotting a 3d model with agents sphere in shape

Hello everyone,

I’m trying to plot my 3D ABM model using abmplot() which seems better for 2d plots rather then 3d as it doesn’t support 3d markers yet but how can I use abmplot() to plot a 3d model if i want to?

Specially how to add 3d marker?

Thank you :slight_smile:

What have you tried at the moment that doesn’t work? As far as I know markers in 3D work fine, see e.g.: 3D Mixed-Agent Ecosystem with Pathfinding · Agents.jl

p.s.: in the future use the tag agents instead of abm when asking questions.

1 Like

so main confusion i have is abmplot() has fields - model, ac, am, as etc. in 2d am = :circle but as it doesn’t take 3d shape :shpere. I looked into Makie and other packages but were not sure if I create sphere using mesh maybe and put in abmplot() with am attribute?

I checked this example that you attached. what I understand is it has two parts for plotting.

First this which creates a static background

const ABMPlot = Agents.get_ABMPlot_type()
function Agents.static_preplot!(ax::Axis3, p::ABMPlot)
    surface!(
        ax,
        (100/205):(100/205):100,
        (100/205):(100/205):100,
        p.abmobs[].model[].heightmap;
        colormap = :terrain
    )
end

and

second which create video

abmvideo(
    "rabbit_fox_hawk.mp4",
    model;
    figure = (size = (800, 700),),
    frames = 300,
    framerate = 15,
    agent_color = animalcolor,
    agent_size = 1.0,
    title = "Rabbit Fox Hawk with pathfinding"
)

Here i didnt understand how does it picked that agents need to be sphere entities? its not exactly defined while plotting. i want something which is more managebale and can be customized. So something like using mesh for different shape and then putting in abmplot for plotting??

In your example the keyword agent_marker is not set. Hence, it has its default value which is :circle. This means, that when plotting in 3D, Makie makes spheres from input specification :circle.

You need to read the documentation of Makie for what else you can provide as a marker for 3D objects. Yes, you can provide meshes as well as far as I know. abmplot does not do anything fancy, it simply propagates these arguments to Makie’s scatter function. Whatever you can use in scatter(x, y, z; marker = something), the same you can use in abmplot.

This is what Im getting.


model = initiation()

colors(a) = a.status == :nothing ? :red : a.status == :activated ? :darkgreen : :orange



fig, ax, abmp = abmplot(model; ac = colors, markers = :sphere)
display(fig) # display figure

Is it this straightforword or need some extra things fro 3d model?

These are model intiation and abmplot output:

StandardABM with 50 agents of type CTL
 agents container: Dict
 space: periodic continuous space with [1.0, 1.0, 1.0] extent and spacing=0.02
 scheduler: fastest
 properties: interaction_radius, activation_prob, dt
(Scene (600px, 450px):
  0 Plots
  1 Child Scene:
    └ Scene (600px, 450px), Axis3(), ABMObservable with model:
StandardABM with 50 agents of type CTL
 agents container: Dict
 space: periodic continuous space with [1.0, 1.0, 1.0] extent and spacing=0.02
 scheduler: fastest
 properties: interaction_radius, activation_prob, dt
and with data collection:
 adata: nothing
 mdata: nothing)

please visit the documentation and consult it accordingly: API · Agents.jl

as you can see there, markers is not a keyword for abmplot. agent_marker is.

You most likely will also have to adjust the size of the marker in 3D, because in 3D makie has different units for what markersize = 2 means. (Note: the keyword is agent_size in abmplot).

1 Like

ok I found issue with agent size. :smiling_face_with_tear: was too big.

fig, ax, abmp = abmplot(ctl_model; ac = ctl_colors, agent_marker = :circle, agent_size = 0.01)

This works perfectly. Thank you :slight_smile: