# \[ANN\]: TernaryDiagrams.jl

**URL:** <https://discourse.julialang.org/t/ann-ternarydiagrams-jl/92312>\
**Category:** Visualization\
**Tags:** package\
**Created:** [December 30, 2022, 12:24pm UTC](https://discourse.julialang.org/t/ann-ternarydiagrams-jl/92312 "2022-12-30T12:24:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elmo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elmo/32/17979_2.png) [@Elmo](https://discourse.julialang.org/u/Elmo)\
**Post date:** [December 30, 2022, 12:24pm UTC](https://discourse.julialang.org/t/ann-ternarydiagrams-jl/92312/1 "2022-12-30T12:24:30Z")

</div>

Hi all! I made a small [Makie recipe package](https://github.com/stelmo/TernaryDiagrams.jl) that allows you to draw [ternary plots](https://en.wikipedia.org/wiki/Ternary_plot) like this:

 ![test](https://global.discourse-cdn.com/julialang/original/3X/4/d/4d9f06c9ab91a9790129319f6cc752e22dad294d.png)

I am planning on eventually making a ternary axis properly (instead of co-opting the regular 2D axis like I do currently), so that there won’t be as much white space around the figure. In the mean time, if you use the package and have any comments, let me know!

---

<div class="post-metadata">

**Author:** ![asinghvi17](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asinghvi17/32/8272_2.png) [@asinghvi17](https://discourse.julialang.org/u/asinghvi17)\
**Post date:** [January 30, 2023, 9:58am UTC](https://discourse.julialang.org/t/ann-ternarydiagrams-jl/92312/2 "2023-01-30T09:58:51Z")

</div>

Just used this, it looks really neat! One potential idea which you could use is to create something like the PolarAxis layoutable, wherein the Scene has a fixed `transform_func` which translates 3D points to 2D points.

I just made this plot for a colorlegend, the output is below:

 ![download-4](https://global.discourse-cdn.com/julialang/original/3X/6/7/67efc0b727ffb8119c7ff21bf5100aecaff2d2f3.png)

with the script (slightly kludgey, I know 🙁)

```julia
xs = LinRange(0, 1, 1000)
ys = LinRange(0, 1, 1000)

barycentric_points = TernaryDiagrams.from_cart_to_bary.(xs, ys')

colors = map(barycentric_points) do barycentric_point
    if any(barycentric_point .< 0.0)
        return RGBf(1,1,1)
    else
        return RGBf(barycentric_point...)
    end
end

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

ternaryaxis!(
    ax;
    labelx = "Bad",
    labely = "Good",
    labelz = "Uncertain",
    xtickformat = tick -> TernaryDiagrams._default_formatter(tick*100)*"%",
    ytickformat = tick -> TernaryDiagrams._default_formatter(tick*100)*"%",
    ztickformat = tick -> Makie.rich(Makie.rich(TernaryDiagrams._default_formatter(tick*100)*"%", color = :black), "--"; color = :white)
);
xlims!(ax, -0.2, 1.2)
ylims!(ax, -0.3, 1.1)
hidedecorations!(ax)
img_plt = image!(ax, xs, ys, colors)
translate!(img_plt, 0, 0, -100)
fig

```

---

<div class="post-metadata">

**Author:** ![Elmo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elmo/32/17979_2.png) [@Elmo](https://discourse.julialang.org/u/Elmo)\
**Post date:** [January 30, 2023, 10:23am UTC](https://discourse.julialang.org/t/ann-ternarydiagrams-jl/92312/3 "2023-01-30T10:23:36Z")

</div>

That is really great! I will definitely look into the way you made the colorlegend. Filling the triangle with colors was by far the hardest part of the entire recipe.

Sadly, I don’t see myself having time for this until mid March, but I will keep you posted!
