update
I’ve figured out how to set colours for certain elements on a plot, but now I don’t know how to make a legend based on these groupings. I am sure I have not done it in the most efficient way, but it works more or less (I don’t know how to make the Target Species line be bolder than others [blue]).
Now I would like to add a legend that shows what category each colour means. I know I need to group things together.
What I thought about trying is this, but I get an error
plot(sol2, tspan=(0.0,2000.0), title = "Biomass through time", xlabel = "Time",;
vars = (Nutrients, Plants, Animals, Target_Animals), linecolor=[:brown, :green, :red, :blue], ylabel = "Biomass", lw=0.3)
MethodError: no method matching u_n(::DiffEqArray{Float64,2,Array{Array{Float64,1},1},Array{Float64,1}}, ::Float64...
My attempt at a minimum working example of I create my array and how I would expect to group it (except I don’t know how to make a minimal example using a differential equation)
num_nutrients = 2
num_plant_species = 15
num_animal_species = 25
target_species = 42
total_species = zeros(num_nutrient+num_plant_species+num_animal_species)
function create_bioS_test(total_species, num_nutrients, num_plant_species, num_animal_species)
bioS_test = zeros(length(total_species))
bioS_test[1:num_nutrients] = rand(Uniform(0,1), num_nutrients)
bioS_test[num_nutrients+1:(num_nutrients+num_plant_species)] = rand(Uniform(0,10), num_plant_species)
bioS_test[(num_nutrients+num_plant_species+1):end] = rand(Uniform(0,10), num_animal_species)
return bioS_test
end
bioS_test = create_bioS_test(total_species, num_nutrients, num_plant_species, num_animal_species)
Nutrients = bioS_test[1:num_nutrients]
Plants = bioS_test[num_nutrients+1:(num_nutrients+num_plant_species)]
Animals = bioS_test[(num_nutrients+num_plant_species+1):end]
Target_Animals = bioS_test[(target_species)]
How I made the graph:
plot(sol2, vars =[1,num_nutrients], linecolor=[:brown], tspan=(0.0,1000.0),;
xlabel = "Time" ,ylabel = "Biomass", lw=0.3)
plot!(sol2, vars = ((num_nutrients+1:(num_nutrients+num_plant_species)), linecolor=[:green], lw=0.3)
plot!(sol2, vars = (((num_nutrients+num_plant_species+1):end), linecolor=[:red], lw=0.3)
plot!(sol2, vars = (target_species), linecolor=[:blue], title = "Biomasses through time", legend=false, lw=0.4)
Any help is appreciated.