-1

I have tried few things by searching but I am missing on the understanding of vertices or something at least brain fade at the moment can some one help me I need a regular hexagon

from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d.art3d import Poly3DCollection, Line3DCollection

fig = plt.figure(figsize=(15,9))
ax = fig.add_subplot(111, projection='3d')

x = [0, 2, 1, 1,1,1]
y = [0, 0, 1, 0, 1,1]
z = [0, 0, 0, 1,1,1]

vertices = [[0, 1, 2], [0, 1, 3], [0, 2, 3], [1, 2, 3],[0,1,2],[0,1,2]]

tupleList = list(zip(x, y, z))

poly3d = [[tupleList[vertices[ix][iy]] for iy in range(len(vertices[0]))] for ix in range(len(vertices))]
ax.scatter(x,y,z)
ax.add_collection3d(Poly3DCollection(poly3d, facecolors='w', linewidths=1, alpha=0.5))
ax.add_collection3d(Line3DCollection(poly3d, colors='k', linewidths=0.2, linestyles=':'))

plt.show()
nithin
  • 753
  • 3
  • 7
  • 21

1 Answers1

-2

Matplotlib is not cabable for real 3D. The 3D stuff in matplotlib is mostly just for a nicer appearance of 2D-data. If you need real 3D visualization i'd recommend Mayavi or VTK.

If your hexagon can not be expressed as a mathematical function of 2 variables (e.g. z = f(x,y) ) then matplotlib is the wrong tool for that.

Easy_Israel
  • 841
  • 6
  • 8