From 5a51e6a5dd2d0a2c38c3cc72fcb5136a4f34c549 Mon Sep 17 00:00:00 2001 From: Victor Liu Date: Fri, 22 Nov 2024 21:22:36 -0500 Subject: [PATCH 1/4] converted ps to array before slicing --- lib/mpl_toolkits/mplot3d/art3d.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/mpl_toolkits/mplot3d/art3d.py b/lib/mpl_toolkits/mplot3d/art3d.py index 44585ccd05e7..9c98f13c6e43 100644 --- a/lib/mpl_toolkits/mplot3d/art3d.py +++ b/lib/mpl_toolkits/mplot3d/art3d.py @@ -1218,6 +1218,7 @@ def _generate_normals(polygons): v2 = np.empty((len(polygons), 3)) for poly_i, ps in enumerate(polygons): n = len(ps) + ps = np.asarray(ps) i1, i2, i3 = 0, n//3, 2*n//3 v1[poly_i, :] = ps[i1, :] - ps[i2, :] v2[poly_i, :] = ps[i2, :] - ps[i3, :] From bdf5514fb0c3ee49cbb1cdf66834dab7a2c58c46 Mon Sep 17 00:00:00 2001 From: Victor Liu Date: Sat, 23 Nov 2024 14:30:11 -0500 Subject: [PATCH 2/4] added test cases for the modification to art3d.py --- lib/mpl_toolkits/mplot3d/tests/test_art3d.py | 31 +++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/mpl_toolkits/mplot3d/tests/test_art3d.py b/lib/mpl_toolkits/mplot3d/tests/test_art3d.py index 4ed48aae4685..bb791f68343e 100644 --- a/lib/mpl_toolkits/mplot3d/tests/test_art3d.py +++ b/lib/mpl_toolkits/mplot3d/tests/test_art3d.py @@ -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(): @@ -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() From 6348165c649e8efb410582025534f73997661666 Mon Sep 17 00:00:00 2001 From: Victor Liu Date: Sat, 7 Dec 2024 15:39:07 -0500 Subject: [PATCH 3/4] modified test for _generate_normals --- lib/mpl_toolkits/mplot3d/tests/test_art3d.py | 30 ++++---------------- 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/lib/mpl_toolkits/mplot3d/tests/test_art3d.py b/lib/mpl_toolkits/mplot3d/tests/test_art3d.py index bb791f68343e..04e756ed9499 100644 --- a/lib/mpl_toolkits/mplot3d/tests/test_art3d.py +++ b/lib/mpl_toolkits/mplot3d/tests/test_art3d.py @@ -57,29 +57,11 @@ def test_zordered_error(): 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 + # Smoke test for https://github.com/matplotlib/matplotlib/issues/29156 + vertices = ((0, 0, 0), (0, 5, 0), (5, 5, 0), (5, 0, 0)) + shape = Poly3DCollection([vertices], edgecolors='r', shade=True) 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() + ax = fig.add_subplot(projection='3d') + ax.add_collection3d(shape) + plt.show() From 3982428df4fed6cb0a6c6ee433e6b8a0d2933e7c Mon Sep 17 00:00:00 2001 From: Victor Liu Date: Sat, 7 Dec 2024 16:04:59 -0500 Subject: [PATCH 4/4] changed plot.show to plot.draw --- lib/mpl_toolkits/mplot3d/tests/test_art3d.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mpl_toolkits/mplot3d/tests/test_art3d.py b/lib/mpl_toolkits/mplot3d/tests/test_art3d.py index 04e756ed9499..4d33636a0b05 100644 --- a/lib/mpl_toolkits/mplot3d/tests/test_art3d.py +++ b/lib/mpl_toolkits/mplot3d/tests/test_art3d.py @@ -64,4 +64,4 @@ def test_generate_normals(): fig = plt.figure() ax = fig.add_subplot(projection='3d') ax.add_collection3d(shape) - plt.show() + plt.draw() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy