@@ -23,7 +23,8 @@ Pkg.status(["Agents", "InteractiveDynamics", "CairoMakie"];
23
23
# straight-forward, and in principle one simply defines functions for how the
24
24
# agents should be plotted. Here we will use a pre-defined model, the Daisyworld
25
25
# as an example throughout this docpage.
26
- # To learn about this model you can visit the [full example](https://juliadynamics.github.io/AgentsExampleZoo.jl/dev/examples/daisyworld/),
26
+ # To learn about this model you can visit the [example hosted at AgentsExampleZoo
27
+ # ](https://juliadynamics.github.io/AgentsExampleZoo.jl/dev/examples/daisyworld/),
27
28
using InteractiveDynamics, Agents
28
29
using CairoMakie
29
30
daisypath = joinpath (dirname (pathof (InteractiveDynamics)), " agents" , " daisyworld_def.jl" )
@@ -149,6 +150,8 @@ abmvideo(
149
150
# always display aggregated collected data as scatterpoints connected with lines.
150
151
# In cases where more granular control over the displayed plots is needed, we need to take
151
152
# a few extra steps and utilize the [`ABMObservable`](@ref) returned by [`abmplot`](@ref).
153
+ # The same steps are necessary when we want to create custom plots that compose
154
+ # animations of the model space and other aspects.
152
155
153
156
# ```@docs
154
157
# ABMObservable
@@ -171,51 +174,53 @@ abmobs
171
174
172
175
#
173
176
174
- # # create a new layout to add new plots to to the right of the abmplot
177
+ # create a new layout to add new plots to to the right of the abmplot
175
178
plot_layout = fig[:,end + 1 ] = GridLayout ()
176
179
177
- # # create a sublayout on its first row and column
180
+ # create a sublayout on its first row and column
178
181
count_layout = plot_layout[1 ,1 ] = GridLayout ()
179
182
180
- # # collect tuples with x and y values for black and white daisys
181
- blacks = @lift (Point2f .($ (p . adf). step, $ (p . adf). count_black))
182
- whites = @lift (Point2f .($ (p . adf). step, $ (p . adf). count_white))
183
+ # collect tuples with x and y values for black and white daisys
184
+ blacks = @lift (Point2f .($ (abmobs . adf). step, $ (abmobs . adf). count_black))
185
+ whites = @lift (Point2f .($ (abmobs . adf). step, $ (abmobs . adf). count_white))
183
186
184
- # # create an axis to plot into and style it to our liking
187
+ # create an axis to plot into and style it to our liking
185
188
ax_counts = Axis (count_layout[1 ,1 ];
186
189
backgroundcolor = :lightgrey , ylabel = " Number of daisies by color" )
187
190
188
- # # plot the data as scatterlines and color them accordingly
191
+ # plot the data as scatterlines and color them accordingly
189
192
scatterlines! (ax_counts, blacks; color = :black , label = " black" )
190
193
scatterlines! (ax_counts, whites; color = :white , label = " white" )
191
194
192
- # # add a legend to the right side of the plot
195
+ # add a legend to the right side of the plot
193
196
Legend (count_layout[1 ,2 ], ax_counts; bgcolor = :lightgrey )
194
197
195
- # # and another plot, written in a more condensed format
198
+ # and another plot, written in a more condensed format
196
199
ax_hist = Axis (plot_layout[2 ,1 ];
197
200
ylabel = " Distribution of mean temperatures\n across all time steps" )
198
- hist! (ax_hist, @lift ($ (p . mdf). temperature);
201
+ hist! (ax_hist, @lift ($ (abmobs . mdf). temperature);
199
202
bins = 50 , color = :red ,
200
203
strokewidth = 2 , strokecolor = (:black , 0.5 ),
201
204
)
202
205
203
206
fig
204
207
205
- # Now, once we step the `p ::ABMObservable`, the whole plot will be updated
206
- Agents. step! (p , 1 )
207
- Agents. step! (p , 1 )
208
+ # Now, once we step the `abmobs ::ABMObservable`, the whole plot will be updated
209
+ Agents. step! (abmobs , 1 )
210
+ Agents. step! (abmobs , 1 )
208
211
fig
209
212
210
213
# Of course, you need to actually adjust axis limits given that the plot is interactive
211
214
autolimits! (ax_counts)
212
215
autolimits! (ax_hist)
213
216
214
217
# Or, simply trigger them on any update to the model observable:
215
- on (p . model) do m
218
+ on (abmobs . model) do m
216
219
autolimits! (ax_counts)
217
220
autolimits! (ax_hist)
218
221
end
219
222
220
- for i in 1 : 100 ; step! (p, 1 ); end
223
+ # and then marvel at everything being auto-updated by calling `step!` :)
224
+
225
+ for i in 1 : 100 ; step! (abmobs, 1 ); end
221
226
fig
0 commit comments