TernaryPlots.jl
TernaryPlots.jl copied to clipboard
support of heatmats
Are heatmaps still possible with the current version? Where can I find an example?
I'm afraid I removed it from the current version because it was so janky. I'm not sure what the best way to go about doing ternary heatmaps would be.
ok. I found some examples with the GMT.jl.
There, however, I cannot specify my own function (e.g. a Distribution) but need to generate a grid which will then be interpolated. I share my code for the grid construction. Maybe it can be useful, as well as the code in GMT.jl.
"""
simplex_grid(m,n=3)
Create a grid across the n-dimesional unit simplex with m points on each dimension.
If `unit=false` then return an Integer grid ranging from 0 to (m-1).
"""
function simplex_grid(m,n=3; unit=true)
n < 2 && error("n needs to be at least 2 but got ", n)
m < 2 && error("m needs to be at least 2 but got ", m)
L = num_compositions(m-1,n)
A = Array{Int}(undef, L, n)
simplex_grid!(A,m-1,n; L)
unit ? A ./(m-1) : A
end
# number of cases for simples_grid
num_compositions(mstep,n) = binomial(n+mstep-1, n-1)
"""
Update matrix A with positions of simplex grid with msteps, i.e. mstep+1 records
for all other dimesnions being 0
"""
function simplex_grid!(A, mstep, n; L=num_compositions(mstep,n))
if n==2
A .= cat(0:mstep, mstep:-1:0; dims=2)
else
istart0 = 0
for im = 0:mstep
Lsub = num_compositions(mstep-im, n-1)
i = istart0.+(1:Lsub)
A[i,1] .= im
# update the remaining columns recursively with decreased mstep
B = @view A[i, 2:n]
simplex_grid!(B, mstep-im, n-1; L=Lsub)
# keep track where to update the next rows
istart0 = istart0 + Lsub
end
end
nothing
end