# Making a triangular plot

**URL:** <https://discourse.julialang.org/t/making-a-triangular-plot/75802>\
**Category:** Visualization\
**Tags:** mesh\
**Created:** [February 4, 2022, 3:07pm UTC](https://discourse.julialang.org/t/making-a-triangular-plot/75802 "2022-02-04T15:07:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)\
**Post date:** [February 4, 2022, 3:07pm UTC](https://discourse.julialang.org/t/making-a-triangular-plot/75802/1 "2022-02-04T15:07:08Z")

</div>

In MATLAB there is a function `triplot` ([2-D triangular plot - MATLAB triplot](https://www.mathworks.com/help/releases/R2021a/matlab/ref/triplot.html)) which can be used to make a triangular plot given a connectivity matrix and the corresponding `(x, y)` values. Is there a similar function in Julia for this purpose? and similarly e.g. for `trimesh` / `trisurf`.

I did see [https://github.com/pazner/Triplot.jl](https://github.com/pazner/Triplot.jl) previously, although it no longer seems to compile on the current version of Julia.

---

<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:** [February 4, 2022, 3:20pm UTC](https://discourse.julialang.org/t/making-a-triangular-plot/75802/2 "2022-02-04T15:20:13Z")

</div>

There is one (and probably more) topic about this matter here in the forum (did a quick search but couldn’t find it/them). But see GMT example [here](https://www.generic-mapping-tools.org/GMT.jl/dev/gallery/ternary/ternary/).

---

<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:** [February 4, 2022, 3:27pm UTC](https://discourse.julialang.org/t/making-a-triangular-plot/75802/3 "2022-02-04T15:27:11Z")

</div>

I think the OP is talking about triangle mesh plots.

@DanielVandH take a look at Meshes.jl and MeshViz.jl if you are interested in triangulations and visualizations of these results. Voronoi-Delaunay triangulations are on the roadmap, but you have other packages out there that generate the connectivities.

> **[GitHub - JuliaGeometry/Meshes.jl: Computational geometry and meshing...](https://github.com/JuliaGeometry/Meshes.jl)**
>
> Computational geometry and meshing algorithms in Julia - GitHub - JuliaGeometry/Meshes.jl: Computational geometry and meshing algorithms in Julia

> **[GitHub - JuliaGeometry/MeshViz.jl: Makie.jl recipes for visualization of...](https://github.com/JuliaGeometry/MeshViz.jl)**
>
> Makie.jl recipes for visualization of Meshes.jl. Contribute to JuliaGeometry/MeshViz.jl development by creating an account on GitHub.

---

<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:** [February 4, 2022, 3:39pm UTC](https://discourse.julialang.org/t/making-a-triangular-plot/75802/4 "2022-02-04T15:39:20Z")

</div>

Ok, then in GMT that is done by the [triangualate](https://www.generic-mapping-tools.org/GMT.jl/dev/#GMT.triangulate) function. Have no example on its usage but would be

```julia
G = triangulate(data, region=(...), spacing=...)

```

where `data` is Mx3 matrix or a `GMTdataset` type and `G` the output grid.

---

<div class="post-metadata">

**Author:** ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)\
**Post date:** [February 4, 2022, 3:49pm UTC](https://discourse.julialang.org/t/making-a-triangular-plot/75802/5 "2022-02-04T15:49:46Z")

</div>

Thanks @juliohm, this was the simplest for me to understand. It’s quite easy to implement with these packages actually (for `triplot`, anyway), e.g:

```julia
"""
    triplot(T, x, y)

Generates and plots a `SimpleMesh` object for a triangulation with triangle connectivity matrix `T` 
and points defined by vectors `x` and `y`. The first output is the `SimpleMesh object, and the 
second plot is the scene containing the plot.
"""
function triplot(T, x, y)
    # Convert into vector of tuples of points 
    points = Meshes.Point2[(x[i], y[i]) for i in 1:length(x)]
    # Connect the points using the provided connectivity matrix T 
    connec = Meshes.connect.([(T[i, 1], T[i, 2], T[i, 3]) for i in 1:size(T, 1)])
    # Mesh 
    mesh = Meshes.SimpleMesh(points, connec)
    h = MeshViz.viz(mesh, showfacets = true)
    return mesh, h
end
mesh, h = triplot(elements, nodes[:, 1], nodes[:, 2])

```
