Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stelmo/ternarydiagrams.jl
Ternary plots with Makie.jl
https://github.com/stelmo/ternarydiagrams.jl
plotting
Last synced: 12 days ago
JSON representation
Ternary plots with Makie.jl
- Host: GitHub
- URL: https://github.com/stelmo/ternarydiagrams.jl
- Owner: stelmo
- License: mit
- Created: 2022-12-18T21:21:01.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-06-09T09:15:11.000Z (7 months ago)
- Last Synced: 2024-07-09T12:13:11.248Z (6 months ago)
- Topics: plotting
- Language: Julia
- Homepage:
- Size: 440 KB
- Stars: 24
- Watchers: 1
- Forks: 3
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TernaryDiagrams
[repostatus-url]: https://www.repostatus.org/#active
[repostatus-img]: https://www.repostatus.org/badges/latest/active.svg[![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl)[![repostatus-img]][repostatus-url]
This package exports a few [Makie](https://github.com/MakieOrg/Makie.jl) recipes
that can be used to construct a (relatively quick and dirty) [ternary
plot](https://en.wikipedia.org/wiki/Ternary_plot).In all the examples that follow, it is assumed that `a1[i] + a2[i] + a3[i] = 1`.
## The ternary axis
```julia
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
```julia
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
```julia
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
```julia
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.```julia
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!