|
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, _all_points_on_plane |
| 6 | +from mpl_toolkits.mplot3d.art3d import Line3DCollection, Poly3DCollection, _all_points_on_plane |
7 | 7 |
|
8 | 8 |
|
9 | 9 | def test_scatter_3d_projection_conservation():
|
@@ -85,3 +85,32 @@ def test_all_points_on_plane():
|
85 | 85 | # All points lie on a plane
|
86 | 86 | points = np.array([[0, 0, 0], [0, 1, 0], [1, 0, 0], [1, 1, 0], [1, 2, 0]])
|
87 | 87 | assert _all_points_on_plane(*points.T)
|
| 88 | + |
| 89 | + |
| 90 | +def test_generate_normals(): |
| 91 | + |
| 92 | + # Following code is an example taken from |
| 93 | + # https://stackoverflow.com/questions/18897786/transparency-for-poly3dcollection-plot-in-matplotlib |
| 94 | + # and modified to test _generate_normals function |
| 95 | + |
| 96 | + fig = plt.figure() |
| 97 | + ax = fig.add_subplot(111, projection='3d') |
| 98 | + |
| 99 | + x = [0, 2, 1, 1] |
| 100 | + y = [0, 0, 1, 0] |
| 101 | + z = [0, 0, 0, 1] |
| 102 | + |
| 103 | + # deliberately use nested tuple |
| 104 | + vertices = ((0, 1, 2), (0, 1, 3), (0, 2, 3), (1, 2, 3)) |
| 105 | + |
| 106 | + tupleList = list(zip(x, y, z)) |
| 107 | + |
| 108 | + poly3d = [[tupleList[vertices[ix][iy]] for iy in range(len(vertices[0]))] |
| 109 | + for ix in range(len(vertices))] |
| 110 | + ax.scatter(x, y, z) |
| 111 | + collection = Poly3DCollection(poly3d, alpha=0.2, edgecolors='r', shade=True) |
| 112 | + face_color = [0.5, 0.5, 1] # alternative: matplotlib.colors.rgb2hex([0.5, 0.5, 1]) |
| 113 | + collection.set_facecolor(face_color) |
| 114 | + ax.add_collection3d(collection) |
| 115 | + |
| 116 | + plt.draw() |
0 commit comments