@@ -18,7 +18,7 @@ Requires `Agents`. See also [`abmvideo`](@ref) and [`abmexploration`](@ref).
18
18
### Agent related
19
19
* `ac, as, am` : These three keywords decide the color, size, and marker, that
20
20
each agent will be plotted as. They can each be either a constant or a *function*,
21
- which takes as an input a single agent and outputs the corresponding value. If the model
21
+ which takes as an input a single agent and outputs the corresponding value. If the model
22
22
uses a `GraphSpace`, `ac, as, am` functions instead take an *iterable of agents* in each
23
23
position (i.e. node of the graph).
24
24
@@ -43,27 +43,28 @@ Requires `Agents`. See also [`abmvideo`](@ref) and [`abmexploration`](@ref).
43
43
* `scatterkwargs = ()` : Additional keyword arguments propagated to the `scatter!` call.
44
44
45
45
### Preplot related
46
- * `heatarray = nothing` : A keyword that plots a heatmap over the space.
46
+ * `heatarray = nothing` : A keyword that plots a model property (that is a matrix)
47
+ as a heatmap over the space.
47
48
Its values can be standard data accessors given to functions like `run!`, i.e.
48
49
either a symbol (directly obtain model property) or a function of the model.
49
- The returned data must be a matrix of the same size as the underlying space.
50
+ If the space is `AbstractGridSpace` then matrix must be the same size as the underlying
51
+ space. For `ContinuousSpace` any size works and will be plotted over the space extent.
50
52
For example `heatarray = :temperature` is used in the Daisyworld example.
51
53
But you could also define `f(model) = create_matrix_from_model...` and set
52
54
`heatarray = f`. The heatmap will be updated automatically during model evolution
53
55
in videos and interactive applications.
54
-
55
- It is strongly recommended to use `abmplot` instead of the `abmplot!` method if
56
- you use `heatarray`, so that a colorbar can be placed naturally.
57
56
* `heatkwargs = NamedTuple()` : Keywords given to `Makie.heatmap` function
58
57
if `heatarray` is not nothing.
59
58
* `add_colorbar = true` : Whether or not a Colorbar should be added to the right side of the
60
- heatmap if `heatarray` is not nothing.
59
+ heatmap if `heatarray` is not nothing. It is strongly recommended to use `abmplot`
60
+ instead of the `abmplot!` method if you use `heatarray`, so that a colorbar can be
61
+ placed naturally.
61
62
* `static_preplot!` : A function `f(ax, model)` that plots something after the heatmap
62
63
but before the agents.
63
- * `osmkwargs = NamedTuple()` : keywords directly passed to `OSMMakie.osmplot!`
64
+ * `osmkwargs = NamedTuple()` : keywords directly passed to `OSMMakie.osmplot!`
64
65
if model space is `OpenStreetMapSpace`.
65
- * `graphplotkwargs = NamedTuple()` : keywords directly passed to
66
- [`GraphMakie.graphplot!`](https://graph.makie.org/stable/#GraphMakie.graphplot)
66
+ * `graphplotkwargs = NamedTuple()` : keywords directly passed to
67
+ [`GraphMakie.graphplot!`](https://graph.makie.org/stable/#GraphMakie.graphplot)
67
68
if model space is `GraphSpace`.
68
69
69
70
The stand-alone function `abmplot` also takes two optional `NamedTuple`s named `figure` and
@@ -82,7 +83,7 @@ The stand-alone function `abmplot` also takes two optional `NamedTuple`s named `
82
83
1. "run": starts/stops the continuous evolution of the model.
83
84
1. "reset model": resets the model to its initial state from right after starting the
84
85
interactive application.
85
- 1. Two sliders control the animation speed: "spu" decides how many model steps should be
86
+ 1. Two sliders control the animation speed: "spu" decides how many model steps should be
86
87
done before the plot is updated, and "sleep" the `sleep()` time between updates.
87
88
* `enable_inspection = add_controls`: If `true`, enables agent inspection on mouse hover.
88
89
* `spu = 1:50`: The values of the "spu" slider.
@@ -132,12 +133,13 @@ end
132
133
abmplot(abmobs::ABMObservable; kwargs...) → fig, ax, abmobs
133
134
abmplot!(ax::Axis/Axis3, abmobs::ABMObservable; kwargs...) → abmobs
134
135
135
- Same functionality as `abmplot(model; kwargs...)`/`abmplot!(ax, model; kwargs...)`
136
+ Same functionality as `abmplot(model; kwargs...)`/`abmplot!(ax, model; kwargs...)`
136
137
but allows to link an already existing `ABMObservable` to the created plots.
137
138
"""
138
- function abmplot (abmobs:: ABMObservable ;
139
- figure = NamedTuple (),
140
- axis = NamedTuple (),
139
+
140
+ function abmplot (abmobs:: ABMObservable ;
141
+ figure = NamedTuple (),
142
+ axis = NamedTuple (),
141
143
kwargs... )
142
144
fig = Figure (; figure... )
143
145
ax = fig[1 ,1 ][1 ,1 ] = agents_space_dimensionality (abmobs. model[]) == 3 ?
@@ -218,6 +220,8 @@ const SUPPORTED_SPACES = Union{
218
220
Agents. GraphSpace,
219
221
}
220
222
223
+
224
+
221
225
function Makie. plot! (abmplot:: _ABMPlot )
222
226
model = abmplot. abmobs[]. model[]
223
227
if ! (model. space isa SUPPORTED_SPACES)
@@ -232,8 +236,8 @@ function Makie.plot!(abmplot::_ABMPlot)
232
236
233
237
# Following attributes are all lifted from the recipe observables (specifically,
234
238
# the model), see lifting.jl for source code.
235
- pos, color, marker, markersize, heatobs =
236
- lift_attributes (abmplot. abmobs[]. model, abmplot. ac, abmplot. as, abmplot. am,
239
+ pos, color, marker, markersize, heatobs =
240
+ lift_attributes (abmplot. abmobs[]. model, abmplot. ac, abmplot. as, abmplot. am,
237
241
abmplot. offset, abmplot. heatarray, abmplot. _used_poly)
238
242
239
243
# OpenStreetMapSpace preplot
@@ -247,7 +251,16 @@ function Makie.plot!(abmplot::_ABMPlot)
247
251
248
252
# Heatmap
249
253
if ! isnothing (heatobs[])
250
- hmap = heatmap! (abmplot, heatobs; colormap = JULIADYNAMICS_CMAP, abmplot. heatkwargs... )
254
+ if ! (model. space isa Agents. ContinuousSpace)
255
+ hmap = heatmap! (abmplot, heatobs; colormap = JULIADYNAMICS_CMAP, abmplot. heatkwargs... )
256
+ else # need special version for continuous space
257
+ nbinx, nbiny = size (heatobs[])
258
+ extx, exty = Agents. abmspace (model). extent
259
+ coordx = range (0 , extx; length = nbinx)
260
+ coordy = range (0 , exty; length = nbiny)
261
+ hmap = heatmap! (abmplot, coordx, coordy, heatobs; colormap = JULIADYNAMICS_CMAP, abmplot. heatkwargs... )
262
+ end
263
+
251
264
if abmplot. add_colorbar[]
252
265
Colorbar (fig[1 , 1 ][1 , 2 ], hmap, width = 20 )
253
266
# TODO : Set colorbar to be "glued" to axis
0 commit comments