python画三角形的高_如何在matplotlib中用三角形顶点的坐标绘制三维三角形(每个三角形9个数字)?...

在像素最多为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()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值