Skip to content
This repository was archived by the owner on Jun 21, 2024. It is now read-only.

Commit fc6a13a

Browse files
committedAug 15, 2022
fix wrong example in agents docpage
1 parent 458154e commit fc6a13a

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed
 

Diff for: ‎Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "InteractiveDynamics"
22
uuid = "ec714cd0-5f51-11eb-0b6e-452e7367ff84"
33
repo = "https://github.com/JuliaDynamics/InteractiveDynamics.jl.git"
4-
version = "0.21.10"
4+
version = "0.21.11"
55

66
[deps]
77
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"

Diff for: ‎docs/src/agents.jl

+21-16
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ Pkg.status(["Agents", "InteractiveDynamics", "CairoMakie"];
2323
# straight-forward, and in principle one simply defines functions for how the
2424
# agents should be plotted. Here we will use a pre-defined model, the Daisyworld
2525
# 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/),
2728
using InteractiveDynamics, Agents
2829
using CairoMakie
2930
daisypath = joinpath(dirname(pathof(InteractiveDynamics)), "agents", "daisyworld_def.jl")
@@ -149,6 +150,8 @@ abmvideo(
149150
# always display aggregated collected data as scatterpoints connected with lines.
150151
# In cases where more granular control over the displayed plots is needed, we need to take
151152
# 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.
152155

153156
# ```@docs
154157
# ABMObservable
@@ -171,51 +174,53 @@ abmobs
171174

172175
#
173176

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
175178
plot_layout = fig[:,end+1] = GridLayout()
176179

177-
## create a sublayout on its first row and column
180+
# create a sublayout on its first row and column
178181
count_layout = plot_layout[1,1] = GridLayout()
179182

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))
183186

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
185188
ax_counts = Axis(count_layout[1,1];
186189
backgroundcolor = :lightgrey, ylabel = "Number of daisies by color")
187190

188-
## plot the data as scatterlines and color them accordingly
191+
# plot the data as scatterlines and color them accordingly
189192
scatterlines!(ax_counts, blacks; color = :black, label = "black")
190193
scatterlines!(ax_counts, whites; color = :white, label = "white")
191194

192-
## add a legend to the right side of the plot
195+
# add a legend to the right side of the plot
193196
Legend(count_layout[1,2], ax_counts; bgcolor = :lightgrey)
194197

195-
## and another plot, written in a more condensed format
198+
# and another plot, written in a more condensed format
196199
ax_hist = Axis(plot_layout[2,1];
197200
ylabel = "Distribution of mean temperatures\nacross all time steps")
198-
hist!(ax_hist, @lift($(p.mdf).temperature);
201+
hist!(ax_hist, @lift($(abmobs.mdf).temperature);
199202
bins = 50, color = :red,
200203
strokewidth = 2, strokecolor = (:black, 0.5),
201204
)
202205

203206
fig
204207

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)
208211
fig
209212

210213
# Of course, you need to actually adjust axis limits given that the plot is interactive
211214
autolimits!(ax_counts)
212215
autolimits!(ax_hist)
213216

214217
# Or, simply trigger them on any update to the model observable:
215-
on(p.model) do m
218+
on(abmobs.model) do m
216219
autolimits!(ax_counts)
217220
autolimits!(ax_hist)
218221
end
219222

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
221226
fig

0 commit comments

Comments
 (0)
This repository has been archived.