versioninfo() import Pkg Pkg.activate(".") Pkg.status() using Polymake using Plots using Distances n = 8 dim = 3 points = rand(Float64, (n,dim)) fig = plot() if dim == 2 plot!(points[:,1],points[:,2], seriestype=:scatter, markersize = 5,legend=false,aspect_ratio =:equal) @show fig end if dim == 3 plot!(points[:,1],points[:,2], points[:,3], seriestype=:scatter, markersize = 5,legend=false,aspect_ratio =:equal) @show fig end distances = Distances.pairwise(Distances.Euclidean(),points,dims=1) a = Polymake.Array(zeros(Int8,n)) filtration = @pm topaz.vietoris_rips_filtration{Rational}(distances, a, 0.1, 4) pershom = topaz.persistent_homology(filtration) inf = 0 for i in 1:length(pershom) if(length(pershom[i])>0) inf = max(inf,maximum(maximum(pershom[i]))) end end inf += 2 x = [] y = [] lines = [] arrows = [] levels = [0] breaklines = [] custom_yticks = [0.0] custom_ylabels = [] level = 1 for (index,dims) in enumerate(pershom) for elements in dims append!(x,[elements[1]]) append!(y,[level]) if(elements[2] == -1) append!(arrows,[[[elements[1], inf], [level, level]]]) else append!(x,[elements[2]]) append!(y,[level]) append!(lines,[[[elements[1], elements[2]], [level, level]]]) end level+=1 end append!(levels,level) append!(breaklines,[[[-0.25,inf],[level, level]]]) append!(custom_ylabels, ["H$(index-1)"]) level+=1 end for i in 2:length(levels) append!(custom_yticks, levels[i-1] + (levels[i]-levels[i-1])/2) end fig = plot() for line in lines plot!(line[1], line[2], linecolor=:steelblue) end for arrow in arrows plot!(arrow[1],arrow[2], arrow = true, linecolor=:steelblue) end for breakline in breaklines[1:size(breaklines,1)-1] plot!(breakline[1],breakline[2], line =:dash, linecolor=:black) end scatter!(x,y,xlims = (-0.25,inf),xticks = 0:1:inf-1, yticks = (custom_yticks[2:size(custom_yticks,1)],custom_ylabels), xlabel="Frame",legend=false) fig x = [] y = [] fig = plot() plot!([-0.25,inf],[-0.25,inf], linecolor=:black,label = "") plot!([-0.25,inf],[inf,inf], line=:dash, linecolor=:black, label = "") for (id,dims) in enumerate(pershom) for (jd,elements) in enumerate(dims) #Splitting the scatter draws to only get legend of initial point in each dimension. Very hacky. if jd == 1 if elements[2] == -1 scatter!([elements.first],[inf],xlims = (-0.25,inf),ylims = (0,inf+1),xticks = 0:1:inf-1, yticks = 0:1:inf-1,label = string(id-1),legend =:bottomright, color=id) else scatter!([elements.first],[elements.second],xlims = (-0.25,inf),ylims = (0,inf+1),xticks = 0:1:inf-1, yticks = 0:1:inf-1,label = string(id-1),legend =:bottomright, color=id) end else append!(x,elements.first) if elements[2] == -1 append!(y,Int(inf)) else append!(y,Int(elements.second)) end end scatter!(x,y,xlims = (-0.25,inf),ylims = (0,inf+1),xticks = 0:1:inf-1, yticks = 0:1:inf-1,label = "", color=id) x = [] y = [] end end fig