JuliaDynamics / InteractiveDynamics.jl

Fast, general-purpose interactive applications for complex systems
https://juliadynamics.github.io/InteractiveDynamics.jl/dev/
MIT License
171 stars 25 forks source link

Plotting overlapping agents only once (when specified) in abmplot to avoid lags #133

Closed ndgnuh closed 1 year ago

ndgnuh commented 1 year ago

How can I disable the plotting of simulated the environment in abmplot/abmexploration?

I think plotting those causes massive lags when the number of agents is large (>= 4000).

Can we plot just one of the agents at each position? most of them are in the same place anyway image

Datseris commented 1 year ago

i am confused. do you want to disable plotting the heatmap related to a model property? That's trivial, just give nothing as the keyword, which is anyways the default value.

But then you say

Can we plot just one of the agents at each position?

which makes me think you are not in the end talking about a spatial property , but rather the agents of the model....?

ndgnuh commented 1 year ago

I'm sorry that the title is misleading.

Yes, I meant the agents of the model, the scatter plot is the one causing the lag.

My current hack is just disabling the scatter completely using this:

function GLMakie.scatter!(a...; k...)
end

But I'm thinking that there should be a way to optionally draw the unique positions only. My current attempt is monkey patching GLMakie.plot!(abmplot::InteractiveDynamics._ABMPlot) like this:

#
            unique_idx::Vector{Int} = indexin(unique(pos[]), pos[])
            scatter!(abmplot, pos[][unique_idx];
                color=color[][unique_idx],
                marker=marker[][unique_idx],
                markersize=markersize,
                abmplot.scatterkwargs...)
# ...

But seems like this is the wrong way to go because the positions won't change over time.

Datseris commented 1 year ago

Okay, then you have the feature request to disable agent plotting.

A second feature request is: when the space is GridSpace, allow the possibility of only plotting one agent per unique position. Unfortunately, I can already tell you that this is not possible, it would require a massive code change. Instead, if we implement your 1st feature request, which is rather trivial, then you can utilize the custom plotting (e.g., the static pre-plot, or custom animations using what is explained in the documentation), to only plot and/or animate one agent per position even if more exist.

ndgnuh commented 1 year ago

Okay, thanks for your reply. I'm too lazy for custom plotting so I worked around this by disabling scatter completely.

function GLMakie.scatter!(a...; k...) 
end