Skip to content

Commit 7527850

Browse files
vicliu2001scottshambaugh
authored andcommitted
added test cases for the modification to art3d.py
1 parent 595fde3 commit 7527850

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

lib/mpl_toolkits/mplot3d/tests/test_art3d.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import matplotlib.pyplot as plt
44

55
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
77

88

99
def test_scatter_3d_projection_conservation():
@@ -85,3 +85,32 @@ def test_all_points_on_plane():
8585
# All points lie on a plane
8686
points = np.array([[0, 0, 0], [0, 1, 0], [1, 0, 0], [1, 1, 0], [1, 2, 0]])
8787
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

Comments
 (0)