ABMEv_plot.jl 3.6 KB
Newer Older
1
using RecipesBase
2
# function designed for Wright Fisher process
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@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
    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))
18
19
20
21
22
23
24
25
26
27
    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 := ""
28
29
            # markersize := 2.3/1000*size(world,1)
            tspan_ar[:],xarray[:]
30
31
32
33
34
35
36
37
38
39
40
41
        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 := ""
42
            # markersize := 2.3/1000*size(world,1)
43
            tspan_ar[:],xarray[:]
44
45
46
47
48
49
50
51
52
53
54
55
56
57
        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 := ""
58
            # markersize := 2.3/1000*size(world,1)
59
            tspan_ar,xarray[:],yarray[:]
60
61
62
63
64
65
66
67
68
69
70
71
72
73
        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 := ""
74
            # markersize := 2.3/1000*size(world,1)
75
            tspan_ar,xarray[:],yarray[:]
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
        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"
94
            p["tspan"],var(world,trait=trait)[:]
95
96
97
98
99
100
101
102
103
        end
    end
    if "vargeo" in what
        @series begin
            linewidth := 2
            seriestype := :line
            label := "Variance of geotrait"
            xlabel := "Time"
            ylabel := "Variance"
104
            p["tspan"],i->first(covgeo(world[:,Int(i)]))
105
106
        end
    end
107
108
109
110
111
112
113
114
115
116
    # if "density_t" in what
    #     @series begin
    #         linewidth := 2
    #         seriestype := :plot3d
    #         label := "Variance of geotrait"
    #         xlabel := "Time"
    #         ylabel := "Variance"
    #         p["tspan"],i->first(covgeo(world[:,Int(i)]))
    #     end
    # end
117
end