Skip to content

stelmo/TernaryDiagrams.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TernaryDiagrams

Aqua QArepostatus-img

This package exports a few Makie recipes that can be used to construct a (relatively quick and dirty) ternary plot.

In all the examples that follow, it is assumed that a1[i] + a2[i] + a3[i] = 1.

The ternary axis

using GLMakie
using TernaryDiagrams
fig = Figure();
ax = Axis(fig[1, 1]);

ternaryaxis!(
    ax; 
    labelx = "a1",
    labely = "a2",
    labelz = "a3",
    # more options available, check out attributes with ?ternaryaxis (same for other plot functions)
    #= Note 
    Depending on the length of the axis labels, they may seem unaligned. 
    Use the kwarg arrow_label_rotation_adjustment to rotate them slightly. 
    For longer labels, use a value closer to 1 (trial and error it).
    =#
)

# the triangle is drawn from (0,0) to (0.5, sqrt(3)/2) to (1,0).
xlims!(ax, -0.2, 1.2) # to center the triangle and allow space for the labels
ylims!(ax, -0.3, 1.1)
hidedecorations!(ax) # to hide the axis decorations
fig


Ternary lines

using GLMakie
using TernaryDiagrams
using JLD2
@load pkgdir(TernaryDiagrams)*"\\test\\data.jld2" a1 a2 a3 mus
a1 = a1[1:20]
a2 = a2[1:20]
a3 = a3[1:20]

fig = Figure()
ax = Axis(fig[1, 1])

ternaryaxis!(ax)
ternarylines!(ax, a1, a2, a3; color = :blue)

xlims!(ax, -0.2, 1.2)
ylims!(ax, -0.3, 1.1)
hidedecorations!(ax)
fig


Ternary scatter

using GLMakie
using TernaryDiagrams
using JLD2
@load pkgdir(TernaryDiagrams)*"\\test\\data.jld2" a1 a2 a3 mus
a1 = a1[1:20]
a2 = a2[1:20]
a3 = a3[1:20]
mus = mus[1:20]

fig = Figure()
ax = Axis(fig[1, 1])

ternaryaxis!(ax)
ternaryscatter!(
    ax,
    a1,
    a2,
    a3;
    color = [get(Makie.ColorSchemes.Spectral, w, extrema(mus)) for w in mus],
    marker = :circle,
    markersize = 20,
)

xlims!(ax, -0.2, 1.2)
ylims!(ax, -0.3, 1.1)
hidedecorations!(ax)
fig


Ternary contours

using GLMakie
using TernaryDiagrams
using JLD2
@load pkgdir(TernaryDiagrams)*"\\test\\data.jld2" a1 a2 a3 mus
a1 = a1[1:20]
a2 = a2[1:20]
a3 = a3[1:20]
mus = mus[1:20]
fig = Figure();
ax = Axis(fig[1, 1]);

ternarycontour!(
    ax,
    a1,
    a2,
    a3,
    mus;
    levels = 5,
    linewidth = 4,
    color = nothing,
    colormap = reverse(Makie.ColorSchemes.Spectral),
    pad_data = true,
)

ternaryaxis!(ax)

xlims!(ax, -0.2, 1.2)
ylims!(ax, -0.3, 1.1)
hidedecorations!(ax)
fig


Ternary filled contours

Note: ternarycontour uses a different Delaunay triangulation scheme to ternarycontourf (the former is made by me, while the latter essentially calls tricontourf from Makie.

using GLMakie
using TernaryDiagrams
using JLD2
@load pkgdir(TernaryDiagrams)*"\\test\\data.jld2" a1 a2 a3 mus
a1 = a1[1:20]
a2 = a2[1:20]
a3 = a3[1:20]
mus = mus[1:20]
fig = Figure();
ax = Axis(fig[1, 1]);
ternarycontourf!(ax, a1, a2, a3, mus; levels = 10)
ternaryaxis!(ax);
xlims!(ax, -0.2, 1.2)
ylims!(ax, -0.3, 1.1)
hidedecorations!(ax)
fig


Long term plans

If you use this package and run into issues, please let me know! I am planning on extending the package to make a ternary plot axis instead of co-opting the regular 2D axis. Before that stage though, I would like to sort out any bugs I currently have implemented. So let me know what you think!

About

Ternary plots with Makie.jl

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages