Skip to content

Commit

Permalink
added test cases for the modification to art3d.py
Browse files Browse the repository at this point in the history
  • Loading branch information
vicliu2001 committed Nov 23, 2024
1 parent 5a51e6a commit bdf5514
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion lib/mpl_toolkits/mplot3d/tests/test_art3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import matplotlib.pyplot as plt

from matplotlib.backend_bases import MouseEvent
from mpl_toolkits.mplot3d.art3d import Line3DCollection
from mpl_toolkits.mplot3d.art3d import Line3DCollection, Poly3DCollection


def test_scatter_3d_projection_conservation():
Expand Down Expand Up @@ -54,3 +54,32 @@ def test_zordered_error():
ax.add_collection(Line3DCollection(lc))
ax.scatter(*pc, visible=False)
plt.draw()


def test_generate_normals():

# Following code is an example taken from
# https://stackoverflow.com/questions/18897786/transparency-for-poly3dcollection-plot-in-matplotlib
# and modified to test _generate_normals function

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

x = [0, 2, 1, 1]
y = [0, 0, 1, 0]
z = [0, 0, 0, 1]

# deliberately use nested tuple
vertices = ((0, 1, 2), (0, 1, 3), (0, 2, 3), (1, 2, 3))

tupleList = list(zip(x, y, z))

poly3d = [[tupleList[vertices[ix][iy]] for iy in range(len(vertices[0]))]
for ix in range(len(vertices))]
ax.scatter(x, y, z)
collection = Poly3DCollection(poly3d, alpha=0.2, edgecolors='r', shade=True)
face_color = [0.5, 0.5, 1] # alternative: matplotlib.colors.rgb2hex([0.5, 0.5, 1])
collection.set_facecolor(face_color)
ax.add_collection3d(collection)

plt.draw()

0 comments on commit bdf5514

Please sign in to comment.