Last active
October 9, 2020 11:01
-
-
Save homerjed/985be9737b07eb72196c004d92ae72f0 to your computer and use it in GitHub Desktop.
Plot a three-dimensional cubic wireframe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
from mpl_toolkits.mplot3d import Axes3D | |
from mpl_toolkits.mplot3d.art3d import Poly3DCollection, Line3DCollection | |
def wireframe(ax): | |
Z = 1.05 * np.array([[-1,+1,-1], [+1,+1,-1], | |
[+1,-1,-1], [-1,-1,-1], | |
[-1,+1,+1], [+1,+1,+1], | |
[+1,-1,+1], [-1,-1,+1]]) | |
verts = [[Z[0],Z[1],Z[2],Z[3]], | |
[Z[4],Z[5],Z[6],Z[7]], | |
[Z[0],Z[1],Z[5],Z[4]], | |
[Z[2],Z[3],Z[7],Z[6]], | |
[Z[1],Z[2],Z[6],Z[5]], | |
[Z[4],Z[7],Z[3],Z[0]]] # return verts | |
ax.add_collection3d(Poly3DCollection(verts, | |
facecolors=(0,0,0,0), | |
linewidths=1, | |
edgecolors='blueviolet')) | |
fig = plt.figure() | |
ax = fig.add_subplot(111, projection='3d') | |
wireframe(ax) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment