|
3 | 3 | importmatplotlib.pyplotasplt
|
4 | 4 |
|
5 | 5 | frommatplotlib.backend_basesimportMouseEvent
|
6 |
| -frommpl_toolkits.mplot3d.art3dimportLine3DCollection |
| 6 | +frommpl_toolkits.mplot3d.art3dimportLine3DCollection,Poly3DCollection |
7 | 7 |
|
8 | 8 |
|
9 | 9 | deftest_scatter_3d_projection_conservation():
|
@@ -54,3 +54,32 @@ def test_zordered_error():
|
54 | 54 | ax.add_collection(Line3DCollection(lc))
|
55 | 55 | ax.scatter(*pc,visible=False)
|
56 | 56 | plt.draw()
|
| 57 | + |
| 58 | + |
| 59 | +deftest_generate_normals(): |
| 60 | + |
| 61 | +# Following code is an example taken from |
| 62 | +# https://stackoverflow.com/questions/18897786/transparency-for-poly3dcollection-plot-in-matplotlib |
| 63 | +# and modified to test _generate_normals function |
| 64 | + |
| 65 | +fig=plt.figure() |
| 66 | +ax=fig.add_subplot(111,projection='3d') |
| 67 | + |
| 68 | +x= [0,2,1,1] |
| 69 | +y= [0,0,1,0] |
| 70 | +z= [0,0,0,1] |
| 71 | + |
| 72 | +# deliberately use nested tuple |
| 73 | +vertices= ((0,1,2), (0,1,3), (0,2,3), (1,2,3)) |
| 74 | + |
| 75 | +tupleList=list(zip(x,y,z)) |
| 76 | + |
| 77 | +poly3d= [[tupleList[vertices[ix][iy]]foriyinrange(len(vertices[0]))] |
| 78 | +forixinrange(len(vertices))] |
| 79 | +ax.scatter(x,y,z) |
| 80 | +collection=Poly3DCollection(poly3d,alpha=0.2,edgecolors='r',shade=True) |
| 81 | +face_color= [0.5,0.5,1]# alternative: matplotlib.colors.rgb2hex([0.5, 0.5, 1]) |
| 82 | +collection.set_facecolor(face_color) |
| 83 | +ax.add_collection3d(collection) |
| 84 | + |
| 85 | +plt.draw() |