I'm plotting a collection of polygons (triangles) using matplotlib's Poly3DCollection. The triangles are between vertices with a color associated with them. I'm currently filling each triangle with a solid color determined by averaging the colors of the three vertices. The triangles are plotted to form a 3D surface mesh.
I would like to fill the triangle with a gradient between all three vertices. The pixel color at a given point would ideally just be linearly interpolated based on the distance to the three points. For example, if there vertices are blue, green and red, the resulting triangle should look like this:
I think this should be possible using matplotlib, but I'm not sure how to do it. If it's not possible, could you suggest another library or approach I could use? Thanks for your help.
EDIT: Additional details
It should work for an arbitrary number of triangles but likely to be less than 2000. The colors are arbitrary, although each vertex will only have one color associated with it. The collection of polygons is created from a list of vertices [x_1, y_1, z_1, x_2, y_2, z_2...]. I can easily change this format as required. The colors associated with each vertex are in a separate list, this can also be easily changed.