I am trying to plot a prism using plot_surface
I have point
- vertices faces
and edges
I have all the data to build, but there is no understanding of how to do it.
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca(projection='3d')
point=np.array([[0,0,1.322876],[1.309307,0,0.1889822],[-0.9819805,0.8660254,0.1889822],[0.1636634,-1.299038,0.1889822],[0.3273268,0.8660254,-0.9449112],[-0.8183171,-0.4330127,-0.9449112]])
faces=np.array([[0,3,1],[2,4,5],[0,1,4,2],[0,2,5,3],[1,3,5,4]])
edges=np.array([[2,4],[1,4],[3,5],[0,2],[2,5],[1,3],[0,1],[0,3],[4,5]])
x=np.array(point[:, 0])
y=np.array(point[:, 1])
z=np.array(point[:, 2])
X, Y = np.meshgrid(x, y)
ax.scatter(x,y,z,depthshade=False)
plt.show()
I would be grateful for any answer
CodePudding user response:
Tried my best with the color
import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d.art3d import Poly3DCollection, Line3DCollection
fig = plt.figure(figsize=(12, 6))
ax = plt.axes(projection='3d')
point=np.array([[0,0,1.322876],[1.309307,0,0.1889822],[-0.9819805,0.8660254,0.1889822],[0.1636634,-1.299038,0.1889822],[0.3273268,0.8660254,-0.9449112],[-0.8183171,-0.4330127,-0.9449112]])
faces=np.array([[0,3,1],[2,4,5],[0,1,4,2],[0,2,5,3],[1,3,5,4]], dtype = 'O')
edges=np.array([[2,4],[1,4],[3,5],[0,2],[2,5],[1,3],[0,1],[0,3],[4,5]])
face3d = [[point[y] for y in x] for x in faces]
edge3d = [[point[y] for y in x] for x in edges]
x=np.array(point[:, 0])
y=np.array(point[:, 1])
z=np.array(point[:, 2])
ax.scatter(x, y, z, marker='.')
for i, p in enumerate(face3d):
if i!=1:
ax.add_collection3d(Poly3DCollection([p], facecolors='red', alpha=0.5))
else:
pass
ax.add_collection3d(Poly3DCollection(face3d[1], facecolors='yellow', alpha=0.5))
ax.add_collection3d(Line3DCollection(edge3d, colors='black', linewidths=1, linestyles='-'))
ax.view_init(-80, 40)
plt.show()