From 67e13786a97c5b26c83a85b7359bc238e0a4506e Mon Sep 17 00:00:00 2001 From: Daniel Vedder <daniel.vedder@idiv.de> Date: Tue, 17 Oct 2023 18:16:31 +0200 Subject: [PATCH] Fixed axis in population plot --- Manifest.toml | 2 +- Project.toml | 3 +-- src/Persefone.jl | 4 +--- src/analysis/makieplots.jl | 18 +++++++++++++++--- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Manifest.toml b/Manifest.toml index 878b002..c5743e1 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -2,7 +2,7 @@ julia_version = "1.9.3" manifest_format = "2.0" -project_hash = "ba06f527c3b60c5d5c4950e08943bcf1017cc1e3" +project_hash = "39bcf21dcc00c4278393aecb66179a3c482a05e5" [[deps.AbstractFFTs]] deps = ["LinearAlgebra"] diff --git a/Project.toml b/Project.toml index ff8ac78..3bf9f92 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Persefone" uuid = "039acd1d-2a07-4b33-b082-83a1ff0fd136" authors = ["Daniel Vedder <daniel.vedder@idiv.de>"] -version = "0.3.0" +version = "0.3.1" [deps] Agents = "46ada45e-f475-11e8-01d0-f70cc89e6671" @@ -18,7 +18,6 @@ ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" -PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3" diff --git a/src/Persefone.jl b/src/Persefone.jl index 69ee02a..da3f1cd 100644 --- a/src/Persefone.jl +++ b/src/Persefone.jl @@ -27,7 +27,6 @@ using GeoArrays, #XXX this is a big dependency - can we get rid of it? Logging, LoggingExtras, - #PrecompileTools, #TODO Random, Serialization, StableRNGs, @@ -115,8 +114,7 @@ include("nature/species/wyvern.jl") include("core/simulation.jl") #this must be last -#XXX precompile? +#XXX precompile? -> PrecompileTools doesn't really give an improvement # https://julialang.org/blog/2021/01/precompile_tutorial/ -# https://julialang.github.io/PrecompileTools.jl/stable/ end diff --git a/src/analysis/makieplots.jl b/src/analysis/makieplots.jl index b914468..3967eeb 100644 --- a/src/analysis/makieplots.jl +++ b/src/analysis/makieplots.jl @@ -43,15 +43,27 @@ Returns a Makie figure object. """ function populationtrends(model::AgentBasedModel) pops = model.datatables["populations"] + # create the labels needed for the ticks on the X axis dates = @param(core.startdate):@param(core.enddate) + ticks = (Int[], String[]) + for i in 1:length(dates) + if Day(dates[i]) == Day(1) + push!(ticks[1], i) + push!(ticks[2], Dates.format(dates[i], "u yy")) + end + end + while length(ticks[1]) > 12 + deleteat!(ticks[1], 2:2:length(ticks[1])) + deleteat!(ticks[2], 2:2:length(ticks[2])) + end + f = Figure() ax = Axis(f[1,1], xlabel="Date", ylabel="Population size", - xtickformat = timeseries -> [Dates.format(dates[Int(d+1)], "dd/mm/yyyy") - for d in timeseries]) + limits=((1, length(dates)), nothing), xticks = ticks) for s in unique(pops.Species) points = @select!(@subset(pops, :Species .== s), :Abundance) lines!(f[1,1], Vector{Float32}(points.Abundance), linewidth=3, label=s) end - axislegend("Species"; position=:lt) + size(pops)[1] > 0 && axislegend("Species"; position=:lt) f end -- GitLab