How precise could tricontourf be?

Based on my understanding, I could input my self-defined triangles to tricontourf so that it will use interpolation to generate contours. But I don’t know the internal logic of interpolation. For example, does it use the triangles’ centre to draw the contour? Also, for interpolation, there are linear interpolation, cosine interpolation, bilinear interpolation, etc. What kind of interpolation do we use for tricontourf?

(I am a starter to this field, please forgive me if the question is stupid)

If a contour level crosses a triangle, only its intersections with the triangle edges are calculated, and these points are connected with straight lines. Linear interpolation along each edge is used to determine the intersection points. The relevant function in the C++ code is at matplotlib/_tri.cpp at 5b87c98e07be94d05a7a5fc2e58b92554e210186 · matplotlib/matplotlib · GitHub.

Thanks for your reply Ian,

To confirm I understand right, if we have triangle-constructed grid like this, and we have the temperature on every intersection, then tricontourf will help us generate the estimated temperature on each of the lateral.

If this is the case, how should we interpolate the temperature inside the triangle?

I don’t think that is what tricontourf does - it decides where to put discrete contours on each triangle edge, not what the values are along the whole edge.

What do you mean by “interpolate the temperature inside the triangle”? Where inside the triangle? Do you just want one temperature for each triangle or do you want the temperature on a grid? It sounds like you want something like scipy.interpolate.LinearNDInterpolator — SciPy v1.7.0 Manual

Thanks for correcting me!

I think I got what you mean - we interpolate discrete values on each triangle edge, then we connect the point with the same value on those edges to generate the contours. Is this correct?

Yes, that is correct.