在像素最多为100万的绘图上绘制1000万个三角形可能没有太大意义。在任何情况下,如果没有关于哪个顶点与哪个顶点相邻的信息,就不能直接使用plot_trisurf方法。在
我看到两种选择:绘制^{}。在
从数据中筛选唯一点并将其提供给^{}。使用此方法,您可能无法根据您的意愿为三角形着色,而只能根据z值。在
以下是如何从输入数据打印Poly3DCollection的示例。为了演示的目的,我们首先需要提供一些样本数据(这需要发问者的职责,而不是回答者的职责)。在import numpy as np
np.set_printoptions(threshold='nan')
phi = np.linspace(0,2*np.pi, 7)
x = np.cos(phi) + np.sin(phi)
y = -np.sin(phi) + np.cos(phi)
z = np.cos(phi)*0.12+0.7
a = np.zeros((len(phi)-1, 9))
a[:,0] = x[:-1]
a[:,1] = y[:-1]
a[:,2] = z[:-1]
a[:,3:6] = np.roll( a[:,0:3], -1, axis=0)
a[:,8] = np.ones_like(phi[:-1])
a = np.around(a, 2)
print a
哪个指纹
^{pr2}$
(每组3列属于一个点,第一列为x,第二列为y,第三列为z)。在
现在我们可以实际构建Poly3Dcollection了。在from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
fc = ["crimson" if i%2 else "gold" for i in range(a.shape[0])]
poly3d = [[ a[i, j*3:j*3+3] for j in range(3) ] for i in range(a.shape[0])]
ax.add_collection3d(Poly3DCollection(poly3d, facecolors=fc, linewidths=1))
ax.set_xlim(-1.5,1.5)
ax.set_ylim(-1.5,1.5)
plt.show()