|
3 | 3 | import matplotlib.pyplot as plt
|
4 | 4 |
|
5 | 5 | from matplotlib.backend_bases import MouseEvent
|
6 |
| -from mpl_toolkits.mplot3d.art3d import Line3DCollection |
| 6 | +from mpl_toolkits.mplot3d.art3d import Line3DCollection, Poly3DCollection |
7 | 7 |
|
8 | 8 |
|
9 | 9 | def test_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 | +def test_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]] for iy in range(len(vertices[0]))] |
| 78 | + for ix in range(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() |
0 commit comments