大佬教程收集整理的这篇文章主要介绍了Matplotlib:用与点关联的颜色绘制三角形,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用 Matplotlib,并且必须绘制一个三角形网格,其中的点在顶点处具有关联颜色。网格必须是二维的,不是三维的,这是我见过的所有 trisurf 示例的规则。
x - x coordiantes of my points
y - y coordiantes of my points
s - values associated with my points (should be colors)
triangles - a List of inDices [i,j,k] that inDicates the triangles.
您能否举例说明,假设上述数据已给定,生成三角形的二维网格(显示或不显示坐标轴)并根据顶点对三角形进行着色?如果线框仍然可见,那就太好了。
它被称为 gouraud shading,并且可用 a.o.通过 matplotlib 的 tripcolor()
。在 matplotlib 中,仅支持将颜色作为给定颜色图中的值。它不是完整的 rgb 平滑。例如 tricontourf()
使用它来插入颜色值。
这是一个简单的例子。
@H_450_21@import matplotlib.pyplot as plt
import matplotlib.tri as tri
x = [1,1,-1,0]
y = [1,0]
s = [0.1,0.75,0.0,0.9,1]
triangles = [[4,1],[4,2],2,3],3,0]]
triang = tri.Triangulation(x,y,triangles)
cmap = plt.cm.rainbow
fig,(ax1,ax2) = plt.subplots(ncols=2,figsize=(12,5))
ax1.triplot(triang,lw=2,zorder=0) # draw the outlines of the triangles
ax1.scatter(x,c=s,cmap=cmap,s=500) # show the colors of the points
ax2.tripcolor(triang,s,shading='gouraud')
plt.show()
以上是大佬教程为你收集整理的Matplotlib:用与点关联的颜色绘制三角形全部内容,希望文章能够帮你解决Matplotlib:用与点关联的颜色绘制三角形所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。