Fill matplotlib polygon with a gradient between vertices

老子叫甜甜 提交于 2020-07-18 05:48:11

问题


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.

来源:https://stackoverflow.com/questions/44526364/fill-matplotlib-polygon-with-a-gradient-between-vertices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!