ABMEv_plot.jl 3.44 KB
Newer Older
1
import Plots:plot,@recipe,@series
2
# function designed for Wright Fisher process
3
4
5
6
7
8
9
10
@recipe function plot(world::Array{U},p;what=["x","H"],trait = 1) where U <: Union{Missing,Agent{T}} where T
    # We reduce time interval if it is too big
    if size(world,2)*size(world,1) > 1e6 && size(world,2) >= 200
        p = copy(p)
        idx_reduced = floor.(Int,range(1,size(world,2),length = 200))
        p["tspan" ] = p["tspan"][idx_reduced]
        world = world[:,idx_reduced]
    end
11
12
    # here  we can take xhist because every agent is updated at the same time
    # world should correspond to a one dimensional array
13
14
15
16
17
18
19
    if count(ismissing,world) > 0
        tspan_ar = vcat([p["tspan"][i]*ones(Int(p["NMax"] - count(ismissing,world[:,i]))) for i in 1:length(p["tspan"]) ]...);
    else
        tspan_ar = repeat(p["tspan"],inner = size(world,1))
    end
    # tspan = Float64.(tspan)
    world = collect(skipmissing(world))
20
21
22
23
24
25
26
27
28
29
    if "x" in what
        @series begin
        xarray = get_xarray(world,trait)
            seriestype := :scatter
            markercolor := "blue"
            markerstrokewidth := 0
            alpha :=.1
            xlabel := "time"
            ylabel := "trait value"
            label := ""
30
31
            # markersize := 2.3/1000*size(world,1)
            tspan_ar[:],xarray[:]
32
33
34
35
36
37
38
39
40
41
42
43
        end
    end
    if "geo" in what
        @series begin
        xarray = get_geo.(world)
            seriestype := :scatter
            markercolor := "blue"
            markerstrokewidth := 0
            alpha :=.1
            xlabel := "time"
            ylabel := "trait value"
            label := ""
44
            # markersize := 2.3/1000*size(world,1)
45
            tspan_ar[:],xarray[:]
46
47
48
49
50
51
52
53
54
55
56
57
58
59
        end
    end
    if "3dgeo" in what
        @series begin
        xarray = get_geo.(world)
        yarray = get_xarray(world,2)
            seriestype := :scatter3d
            markercolor := "blue"
            markerstrokewidth := 0
            alpha :=.1
            xlabel := "time"
            ylabel := "geotrait"
            zlabel := "trait value"
            label := ""
60
            # markersize := 2.3/1000*size(world,1)
61
            tspan_ar,xarray[:],yarray[:]
62
63
64
65
66
67
68
69
70
71
72
73
74
75
        end
    end
    if "3d" in what
        @series begin
        xarray = get_xarray(world,1)
        yarray = get_xarray(world,2)
            seriestype := :scatter3d
            markercolor := "blue"
            markerstrokewidth := 0
            alpha :=.1
            xlabel := "time"
            ylabel := "position"
            zlabel := "trait value"
            label := ""
76
            # markersize := 2.3/1000*size(world,1)
77
            tspan_ar,xarray[:],yarray[:]
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
        end
    end
    # if "H" in what
    #     @series begin
    #         x = get_x.(world,trait)
    #         linewidth := 2
    #         seriestype := :line
    #         label := "Interconnectedness"
    #         tspan,N^2 / 2 .* [H_discrete(x[:,i]) for i in tspan]
    #     end
    # end
    if "var" in what
        @series begin
            linewidth := 2
            seriestype := :line
            label := "Variance"
            xlabel := "Time"
            ylabel := "Variance"
96
            p["tspan"],var(world,trait=trait)[:]
97
98
99
100
101
102
103
104
105
        end
    end
    if "vargeo" in what
        @series begin
            linewidth := 2
            seriestype := :line
            label := "Variance of geotrait"
            xlabel := "Time"
            ylabel := "Variance"
106
            p["tspan"],i->first(covgeo(world[:,Int(i)]))
107
108
109
        end
    end
end