ABMEv_plot.jl 3.87 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using Plots
# function designed for Wright Fisher process
@recipe function plot(world::Array{Agent{T}},p;what=["x","H"],trait = 1) where T
    # here  we can take xhist because every agent is updated at the same time
    # world should correspond to a one dimensional array
    N = size(world,1)
    tspan = collect(1:Int(p["tend"]))
    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 := ""
            markersize := 2.3/1000*size(world,1)
            repeat(tspan,inner = N),xarray[:]
        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 := ""
            markersize := 2.3/1000*size(world,1)
            repeat(tspan,inner = N),xarray[:]
        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 := ""
            markersize := 2.3/1000*size(world,1)
            repeat(tspan,inner = N),xarray[:],yarray[:]
        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 := ""
            markersize := 2.3/1000*size(world,1)
            repeat(tspan,inner = N),xarray[:],yarray[:]
        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"
            tspan,var(world,trait=trait)[:]
        end
    end
    if "vargeo" in what
        @series begin
            linewidth := 2
            seriestype := :line
            label := "Variance of geotrait"
            xlabel := "Time"
            ylabel := "Variance"
            tspan,i->first(covgeo(world[:,Int(i)]))
        end
    end
end

@recipe function plot(world::Array{Union{Agent{T},Missing}},p;what=["x","H"],trait = 1) where T
    # here world should correspond to a multidimensional array
    xarray = vcat(get_x.(skipmissing(world),trait)...)
    N = size(xarray,1)
    tspan = p["tspan"]
    tspanarray = vcat([tspan[i]*ones(Int(p["NMax"] - count(ismissing,world[:,i]))) for i in 1:length(tspan) ]...)
    if "x" in what
        @series begin
            seriestype := :scatter
            markercolor := "blue"
            markerstrokewidth := 0
            alpha :=.1
            xlabel := "time"
            ylabel := "trait value"
            label := ""
            markersize := 2.3/1000*size(world,1)
            tspanarray,xarray
        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
end