# Ternary diagrams and surfaces on non-rectangular grids

**URL:** https://discourse.julialang.org/t/ternary-diagrams-and-surfaces-on-non-rectangular-grids/43423
**Category:** Visualization
**Tags:** question
**Created:** [July 21, 2020, 10:05am UTC](https://discourse.julialang.org/t/ternary-diagrams-and-surfaces-on-non-rectangular-grids/43423 "2020-07-21T10:05:51Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![SEA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sea/32/8956_2.png) [@SEA](https://discourse.julialang.org/u/SEA)
#### Post date: [July 21, 2020, 10:05am UTC](https://discourse.julialang.org/t/ternary-diagrams-and-surfaces-on-non-rectangular-grids/43423/1 "2020-07-21T10:05:52Z")

</div>

I would like to plot a surface on a triangular domain. Is there a Julia project which can plot [ternary diagrams](https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/2299/versions/2/screenshot.jpg), akin to [this code](https://github.com/alchemyst/ternplot)?

---

<div class="post-metadata">

### Author: ![EvoArt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evoart/32/25357_2.png) [@EvoArt](https://discourse.julialang.org/u/EvoArt)
#### Post date: [April 4, 2021, 3:12pm UTC](https://discourse.julialang.org/t/ternary-diagrams-and-surfaces-on-non-rectangular-grids/43423/2 "2021-04-04T15:12:10Z")

</div>

Maybe PGFplotsX? I managed to get something close to that example plotting directly in pgfplots in LaTeX. But the edges of the triangle were jagged as the surface was composed of squares. I’m sure Somone with more knowhow could do better!

---

<div class="post-metadata">

### Author: ![EvoArt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evoart/32/25357_2.png) [@EvoArt](https://discourse.julialang.org/u/EvoArt)
#### Post date: [April 4, 2021, 3:44pm UTC](https://discourse.julialang.org/t/ternary-diagrams-and-surfaces-on-non-rectangular-grids/43423/3 "2021-04-04T15:44:20Z")

</div>

Also, @lazarusA you seem to be a plotting master craftsman! Any ideas?

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [April 4, 2021, 8:33pm UTC](https://discourse.julialang.org/t/ternary-diagrams-and-surfaces-on-non-rectangular-grids/43423/4 "2021-04-04T20:33:14Z")

</div>

[GMT.jl](https://github.com/GenericMappingTools/GMT.jl) is possibly one of the best bets for this and @joa-quim is the guru.  
See a simpler example [here](https://discourse.julialang.org/t/contour-plot-for-non-rectangular-domain/57381/5) but package goes miles beyond in terms of plots layout complexity.

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [April 4, 2021, 11:02pm UTC](https://discourse.julialang.org/t/ternary-diagrams-and-surfaces-on-non-rectangular-grids/43423/5 "2021-04-04T23:02:35Z")

</div>

That example was one to show how one can easily clip the display area to any form, but if Ternary plots are wanted then GMT has [this module](https://docs.generic-mapping-tools.org/dev/ternary.html) that is wrapped in GMT.jl in the `ternary` module that has the same syntax as `plot` but I have not experimented it.

---

<div class="post-metadata">

### Author: ![EvoArt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evoart/32/25357_2.png) [@EvoArt](https://discourse.julialang.org/u/EvoArt)
#### Post date: [April 4, 2021, 11:28pm UTC](https://discourse.julialang.org/t/ternary-diagrams-and-surfaces-on-non-rectangular-grids/43423/6 "2021-04-04T23:28:04Z")

</div>

This looks great. I’d never heard of GMT. But now I’m dreaming up reasons to include maps in publications!

---

<div class="post-metadata">

### Author: ![EvoArt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evoart/32/25357_2.png) [@EvoArt](https://discourse.julialang.org/u/EvoArt)
#### Post date: [April 4, 2021, 11:30pm UTC](https://discourse.julialang.org/t/ternary-diagrams-and-surfaces-on-non-rectangular-grids/43423/7 "2021-04-04T23:30:12Z")

</div>

I’m assuming the OP @SEA is interested in replicating this 3d surface

 ![screenshot](https://global.discourse-cdn.com/julialang/original/3X/2/c/2c72abd05269f07291df32b42a489106956f65ed.png)

---

<div class="post-metadata">

### Author: ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)
#### Post date: [April 4, 2021, 11:30pm UTC](https://discourse.julialang.org/t/ternary-diagrams-and-surfaces-on-non-rectangular-grids/43423/8 "2021-04-04T23:30:38Z")

</div>

Out of curiosity, what’s the advantage of plotting on a triangle versus on the more common rectangular coordinates? It seems like they’d be equivalent, each having two degrees of freedom.

---

<div class="post-metadata">

### Author: ![EvoArt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evoart/32/25357_2.png) [@EvoArt](https://discourse.julialang.org/u/EvoArt)
#### Post date: [April 4, 2021, 11:38pm UTC](https://discourse.julialang.org/t/ternary-diagrams-and-surfaces-on-non-rectangular-grids/43423/9 "2021-04-04T23:38:24Z")

</div>

On a 2d ternary plot, if there is a fixed sum of all variables (e.g. the proportions of 3 competing Game theoretic strategies) you can represent each of 3 variable by the distance to each axis. with a surface on top, you can also show how some 4varable depends on the other 3.

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [April 4, 2021, 11:50pm UTC](https://discourse.julialang.org/t/ternary-diagrams-and-surfaces-on-non-rectangular-grids/43423/10 "2021-04-04T23:50:17Z")

</div>

I’m not sure you can plot islolines in ternary plots with GMT. You can plot the whole collection of symbols but I don’t see a way to plot lines. If interested, raise this issue in the GMT forum.

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [April 5, 2021, 5:23am UTC](https://discourse.julialang.org/t/ternary-diagrams-and-surfaces-on-non-rectangular-grids/43423/11 "2021-04-05T05:23:12Z")

</div>

See possibly one example [here](https://www.google.com/url?sa=t&source=web&rct=j&url=http://www-udc.ig.utexas.edu/external/becker/plot_ternary.pdf&ved=2ahUKEwiz0qnRrebvAhV9_rsIHXzFCLAQFjAAegQIBBAC&usg=AOvVaw3nMITQ9h-iCdWgARHppIz5), a pdf with GMT ternary plot examples which also points to gmt scripts [here](http://geodynamics.usc.edu/~becker/software/plot_ternary).

---

<div class="post-metadata">

### Author: ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)
#### Post date: [April 5, 2021, 9:08pm UTC](https://discourse.julialang.org/t/ternary-diagrams-and-surfaces-on-non-rectangular-grids/43423/12 "2021-04-05T21:08:25Z")

</div>

If your surface is of equation z=f(a,b,c), where (a,b,c) are barycentric coordinates (i.e. a+b+c=1, a, b, c \>=0), of the points in the planar triangular region of definition for f, then if you are defining a uniform triangulation of this region (with points expressed in cartesian coordinates, and then converted to barycentric ones) and lift the points of the triangulation onto the surface, you get a mesh defined on the surface and can plot it with Makie. For triangulation you can use Triangulate.js

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [April 6, 2021, 12:46am UTC](https://discourse.julialang.org/t/ternary-diagrams-and-surfaces-on-non-rectangular-grids/43423/13 "2021-04-06T00:46:05Z")

</div>

There is TernaryPlots.jl under development in pure Julia, we had this discussion over Zulip recently in this thread: [Zulip](https://julialang.zulipchat.com/#narrow/stream/225542-helpdesk/topic/Can.20a.20recipe.20be.20used.20for.20ternary.20plots.3F)

There you can find screenshots of what is currently possible. It looks great.
