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

**URL:** <https://discourse.julialang.org/t/using-abmplot-for-plotting-a-3d-model-with-agents-sphere-in-shape/113941>\
**Category:** New to Julia\
**Tags:** visualization, agents, modelling\
**Created:** [May 7, 2024, 11:22am UTC](https://discourse.julialang.org/t/using-abmplot-for-plotting-a-3d-model-with-agents-sphere-in-shape/113941 "2024-05-07T11:22:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [May 7, 2024, 11:22am UTC](https://discourse.julialang.org/t/using-abmplot-for-plotting-a-3d-model-with-agents-sphere-in-shape/113941/1 "2024-05-07T11:22:57Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [May 7, 2024, 12:14pm UTC](https://discourse.julialang.org/t/using-abmplot-for-plotting-a-3d-model-with-agents-sphere-in-shape/113941/2 "2024-05-07T12:14:24Z")

</div>

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](https://juliadynamics.github.io/Agents.jl/stable/examples/rabbit_fox_hawk/)

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

---

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [May 7, 2024, 1:34pm UTC](https://discourse.julialang.org/t/using-abmplot-for-plotting-a-3d-model-with-agents-sphere-in-shape/113941/3 "2024-05-07T13:34:57Z")

</div>

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

```julia
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

```julia
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??

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [May 7, 2024, 1:43pm UTC](https://discourse.julialang.org/t/using-abmplot-for-plotting-a-3d-model-with-agents-sphere-in-shape/113941/4 "2024-05-07T13:43:12Z")

</div>

> [@Sahil\_Khan](#):
>
> Here i didnt understand how does it picked that agents need to be sphere entities?

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`.

---

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [May 7, 2024, 1:47pm UTC](https://discourse.julialang.org/t/using-abmplot-for-plotting-a-3d-model-with-agents-sphere-in-shape/113941/5 "2024-05-07T13:47:52Z")

</div>

This is what Im getting.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/f/7/f742fd6037a7feb31883017dd2afd5b6f149a222.jpeg)

```julia

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:

```julia
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

```

```julia
(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)

```

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [May 7, 2024, 1:55pm UTC](https://discourse.julialang.org/t/using-abmplot-for-plotting-a-3d-model-with-agents-sphere-in-shape/113941/6 "2024-05-07T13:55:35Z")

</div>

> [@Sahil\_Khan](#):
>
> `abmplot(model; ac = colors, markers = :sphere)`

please visit the documentation and consult it accordingly: [API · Agents.jl](https://juliadynamics.github.io/Agents.jl/stable/api/#Agents.abmplot)

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`).

---

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [May 7, 2024, 2:03pm UTC](https://discourse.julialang.org/t/using-abmplot-for-plotting-a-3d-model-with-agents-sphere-in-shape/113941/8 "2024-05-07T14:03:06Z")

</div>

ok I found issue with agent size. 🥲 was too big.

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

```

This works perfectly. Thank you 🙂
