File Exchange

image thumbnail

Contour Plot for Scattered Data

version (3.78 KB) by Duane Hanselman
Triangular Contour Plot


Updated 31 Oct 2012

View License

TRICONTOUR(TRI,X,Y,Z,N) draws scalar N contour lines treating the values in Z as heights above a plane. TRI,X,Y,and Z define a triangulation where the triangles are defined by the M-by-3 face matrix TRI, such as that returned by DELAUNAY. Each row of TRI contains indices into the X,Y, and Z vertex vectors to define a single triangular face. Contours are computed directly from the triangulation rather than interpolating back to a cartesian grid using GRIDDATA.
TRICONTOUR(TRI,X,Y,Z,V) draws length(V) contour lines at the values specified in vector V.
TRICONTOUR(TRI,X,Y,Z,[v v]) draws a single contour line at the level v.
[C,H] = TRICONTOUR(...) returns contour matrix C as described in CONTOURC and a vector of handles H to the created patch objects.
H can be used to set patch properties.
CLABEL(C) or CLABEL(C,H) labels the contour levels.

Cite As

Duane Hanselman (2020). Contour Plot for Scattered Data (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (14)

Gabriel Barros

Josh Philipson

Thank you, Duane!!


did anyone find a fix for :

do you know why clabel(c,h) does not work?

Error using clabel (line 77)
Not enough contour handles.




Your examples do not work for me. I get the error message "xxx dodgy iterations". Any idea of what could be happening?

Tianshu Yu



do you know why clabel(c,h) does not work?

Error using clabel (line 77)
Not enough contour handles.


youssef aider


Hi. Great function!
How do i turn on the option to fill the contours? I'm only getting the isolines.



Very useful, Thank you!

Mitrofan Curti

It is a pity MATLAB doesn't have a function like that yet. I usually avoid using functions from fileexchange but this one was really necessary for me. Smart way of leaving the option to insert the values for the contours, as I have a figure from parts so I can fix the values and keep the contours continuous


Ludger Suarez-Burgoa

Useful function in order to display contour lines from a TIN (equivalent to a Delaunay triangulation) without converting the TIN into a regular mesh.

Rick van Rijn


Exactly what I was looking for.

MATLAB Release Compatibility
Created with R14
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!