Skip to content

Commit bdf5514

Browse files
committed
added test cases for the modification to art3d.py
1 parent 5a51e6a commit bdf5514

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
6+
from mpl_toolkits.mplot3d.art3d import Line3DCollection, Poly3DCollection
77

88

99
def test_scatter_3d_projection_conservation():
@@ -54,3 +54,32 @@ def test_zordered_error():
5454
ax.add_collection(Line3DCollection(lc))
5555
ax.scatter(*pc, visible=False)
5656
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

Comments
 (0)