# Triangular patches in Plots

**URL:** https://discourse.julialang.org/t/triangular-patches-in-plots/6406
**Category:** General Usage
**Created:** [October 12, 2017, 9:39am UTC](https://discourse.julialang.org/t/triangular-patches-in-plots/6406 "2017-10-12T09:39:29Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Philippe\_Maincon](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@Philippe\_Maincon](https://discourse.julialang.org/u/Philippe_Maincon)
#### Post date: [October 12, 2017, 9:39am UTC](https://discourse.julialang.org/t/triangular-patches-in-plots/6406/1 "2017-10-12T09:39:29Z")

</div>

Hi,  
I am learning to use Plots.jl these days, to visualise output from FEM analysis.

One thing I would like to be able to do is provide 3 “nodes” (in 2D, in my case, but 3D is an obvious extension) and 3 values or colors, and get a triangle, colored by linear interpolation. My visualisation will require hundreds or thousands of such patches.

In Matlab, this type of functionality is provided by “patch()”.

Is there a way to do this in Plots? If not, do you know whether GR could do this?

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [October 12, 2017, 9:53am UTC](https://discourse.julialang.org/t/triangular-patches-in-plots/6406/2 "2017-10-12T09:53:02Z")

</div>

This is not an answer to your questions but for large meshes I would recommend writing to VTK files using [https://github.com/jipolanco/WriteVTK.jl](https://github.com/jipolanco/WriteVTK.jl) and open them in Paraview. It is an excellent tool to learn especially if you want to go over to 3d visualizations later.

---

<div class="post-metadata">

### Author: ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)
#### Post date: [October 12, 2017, 10:01am UTC](https://discourse.julialang.org/t/triangular-patches-in-plots/6406/3 "2017-10-12T10:01:22Z")

</div>

May not exactly be the fastest or best option out there but check out [VTKDataTypes](https://github.com/mohamed82008/VTKDataTypes.jl/) and [VTKDataIO](https://github.com/mohamed82008/VTKDataIO.jl). You can create your data structure using VTKDataTypes and then either visualize it directly using VTKDataIO or change it to a form that can be visualized with GLVisualize using the GLMesh function.

---

<div class="post-metadata">

### Author: ![Philippe\_Maincon](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@Philippe\_Maincon](https://discourse.julialang.org/u/Philippe_Maincon)
#### Post date: [October 12, 2017, 10:29am UTC](https://discourse.julialang.org/t/triangular-patches-in-plots/6406/4 "2017-10-12T10:29:05Z")

</div>

Hi guys,

thanks. I am aware of Paraview. For now, with 100 to 1000 patches, this would be swatting a fly with a sledgehammer.

But thank you for the tip about WriteVTK.jl, I take note.

Patches in Plot or GR, anyone?

---

<div class="post-metadata">

### Author: ![Philippe\_Maincon](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@Philippe\_Maincon](https://discourse.julialang.org/u/Philippe_Maincon)
#### Post date: [October 12, 2017, 10:31am UTC](https://discourse.julialang.org/t/triangular-patches-in-plots/6406/5 "2017-10-12T10:31:31Z")

</div>

And thank you Mohamed for the tip on VTKDataTypes!

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [October 12, 2017, 1:13pm UTC](https://discourse.julialang.org/t/triangular-patches-in-plots/6406/6 "2017-10-12T13:13:30Z")

</div>

> [@Philippe\_Maincon](#):
>
> Is there a way to do this in Plots? If not, do you know whether GR could do this?

No and no. Relevant issues:

> <https://github.com/JuliaPlots/Plots.jl/issues/392>
>
> I really like the idea of this package and I am more and more relying upon it. T…hese is one type of plots however that I encounter very frequently in my work and that does not seem to be supported by plots.jl: an interface for the plotting of triangular meshes in 3d. At least the PyPlot and PlotsJS backends provide support through their \`trisurf\_plot\` and \`mesh3d\` API's, respectively. This leaves me with a mix of Plots calls and direct backend invocations.
> 
> Is this somehow already supported or are there any plans to support this API in the future?

> <https://github.com/jheinen/GR.jl/issues/31>
>
> It would be nice to be able to set the triangles in trisurf. For example, and ar…ray triangles is usually given as:
> 
> \`\`\`
> triangles = \[node1 node2 node3
> node4 node5 node6
> ...\]
> \`\`\`
> 
> where this means that for
> 
> \`\`\`
> plot(x,y,z,triangles=triangles)
> \`\`\`
> 
> we have that \`(x\[node1\],y\[node1\],z\[node1\])\`, \`(x\[node2\],y\[node2\],z\[node2\])\`, and \`(x\[node3\],y\[node3\],z\[node3\])\` are the points which make the first triangle, etc. The reason for this is referenced in tbreloff/Plots.jl#392

As shown in the issues. PyPlot.jl can do it directly but Plots.jl doesn’t support it yet. If I ever understand how to add attributes in Plots.jl this would be the PR I’d work on.

---

<div class="post-metadata">

### Author: ![Philippe\_Maincon](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@Philippe\_Maincon](https://discourse.julialang.org/u/Philippe_Maincon)
#### Post date: [October 12, 2017, 1:15pm UTC](https://discourse.julialang.org/t/triangular-patches-in-plots/6406/7 "2017-10-12T13:15:27Z")

</div>

OK, good to know that this is the situation for now. Thanks

---

<div class="post-metadata">

### Author: ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)
#### Post date: [October 12, 2017, 4:52pm UTC](https://discourse.julialang.org/t/triangular-patches-in-plots/6406/8 "2017-10-12T16:52:37Z")

</div>

Sounds great 🙂
