@@ -1984,47 +1984,30 @@ def plot_trisurf(self, *args, **kwargs):
1984
1984
args = args [1 :]
1985
1985
1986
1986
triangles = tri .get_masked_triangles ()
1987
- xt = tri .x [triangles ][..., np . newaxis ]
1988
- yt = tri .y [triangles ][..., np . newaxis ]
1989
- zt = z [triangles ][..., np . newaxis ]
1987
+ xt = tri .x [triangles ]
1988
+ yt = tri .y [triangles ]
1989
+ zt = z [triangles ]
1990
1990
1991
- verts = np .concatenate ((xt , yt , zt ), axis = 2 )
1992
-
1993
- # Only need these vectors to shade if there is no cmap
1994
- if cmap is None and shade :
1995
- totpts = len (verts )
1996
- v1 = np .empty ((totpts , 3 ))
1997
- v2 = np .empty ((totpts , 3 ))
1998
- # This indexes the vertex points
1999
- which_pt = 0
2000
-
2001
- colset = []
2002
- for i in xrange (len (verts )):
2003
- avgzsum = verts [i ,0 ,2 ] + verts [i ,1 ,2 ] + verts [i ,2 ,2 ]
2004
- colset .append (avgzsum / 3.0 )
2005
-
2006
- # Only need vectors to shade if no cmap
2007
- if cmap is None and shade :
2008
- v1 [which_pt ] = np .array (verts [i ,0 ]) - np .array (verts [i ,1 ])
2009
- v2 [which_pt ] = np .array (verts [i ,1 ]) - np .array (verts [i ,2 ])
2010
- which_pt += 1
2011
-
2012
- if cmap is None and shade :
2013
- normals = np .cross (v1 , v2 )
2014
- else :
2015
- normals = []
1991
+ # verts = np.stack((xt, yt, zt), axis=-1)
1992
+ verts = np .concatenate ((
1993
+ xt [..., np .newaxis ], yt [..., np .newaxis ], zt [..., np .newaxis ]
1994
+ ), axis = - 1 )
2016
1995
2017
1996
polyc = art3d .Poly3DCollection (verts , * args , ** kwargs )
2018
1997
2019
1998
if cmap :
2020
- colset = np .array (colset )
2021
- polyc .set_array (colset )
1999
+ # average over the three points of each triangle
2000
+ avg_z = verts [:, :, 2 ].mean (axis = 1 )
2001
+ polyc .set_array (avg_z )
2022
2002
if vmin is not None or vmax is not None :
2023
2003
polyc .set_clim (vmin , vmax )
2024
2004
if norm is not None :
2025
2005
polyc .set_norm (norm )
2026
2006
else :
2027
2007
if shade :
2008
+ v1 = verts [:, 0 , :] - verts [:, 1 , :]
2009
+ v2 = verts [:, 1 , :] - verts [:, 2 , :]
2010
+ normals = np .cross (v1 , v2 )
2028
2011
colset = self ._shade_colors (color , normals )
2029
2012
else :
2030
2013
colset = color
0 commit comments