【发布时间】:2026-01-25 00:05:01
【问题描述】:
我正在尝试将颜色图应用于 3d 多边形。 多边形很好,显示在正确的位置。 我唯一不能做的就是用渐变填充它。
这是我的代码:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.colors import LinearSegmentedColormap
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
fig = plt.figure()
ax = Axes3D(fig)
x = [0,0,0]
y = [0,1,0]
z = [0,0,1]
verts = [zip(x, y,z)] #(0,0,0) (0,1,0) (0,0,1)
colors = ['red', 'gray', 'gray', 'green']
index = [0.0, 0.49, 0.509, 1.0]
cm = LinearSegmentedColormap.from_list('my_colormap', zip(index, colors))
collection = Poly3DCollection(verts, cmap=cm)
ax.add_collection3d(collection)
plt.show()
有人可以帮帮我吗?
编辑:
此外,渐变应该看起来像this
【问题讨论】:
标签: python matplotlib 3d polygon