@@ -650,6 +650,8 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
650650 self ._path_collection_id += 1
651651
652652 def draw_gouraud_triangle (self , gc , points , colors , trans ):
653+ # docstring inherited
654+
653655 # This uses a method described here:
654656 #
655657 # http://www.svgopen.org/2005/papers/Converting3DFaceToSVG/index.html
@@ -685,9 +687,9 @@ def draw_gouraud_triangle(self, gc, points, colors, trans):
685687 ' \n 1 1 1 1 0 \n 0 0 0 0 1 ' )
686688 writer .end ('filter' )
687689
688- avg_color = np .sum (colors [:, :], axis = 0 ) / 3.0
689- # Just skip fully-transparent triangles
690- if avg_color [ - 1 ] == 0.0 :
690+ avg_color = np .average (colors , axis = 0 )
691+ if avg_color [ - 1 ] == 0 :
692+ # Skip fully-transparent triangles
691693 return
692694
693695 trans_and_flip = self ._make_flip_transform (trans )
@@ -698,7 +700,7 @@ def draw_gouraud_triangle(self, gc, points, colors, trans):
698700 x1 , y1 = tpoints [i ]
699701 x2 , y2 = tpoints [(i + 1 ) % 3 ]
700702 x3 , y3 = tpoints [(i + 2 ) % 3 ]
701- c = colors [i ][: ]
703+ rgba_color = colors [i ]
702704
703705 if x2 == x3 :
704706 xb = x2
@@ -723,12 +725,13 @@ def draw_gouraud_triangle(self, gc, points, colors, trans):
723725 writer .element (
724726 'stop' ,
725727 offset = '1' ,
726- style = generate_css ({'stop-color' : rgb2hex (avg_color ),
727- 'stop-opacity' : short_float_fmt (c [- 1 ])}))
728+ style = generate_css ({
729+ 'stop-color' : rgb2hex (avg_color ),
730+ 'stop-opacity' : short_float_fmt (rgba_color [- 1 ])}))
728731 writer .element (
729732 'stop' ,
730733 offset = '0' ,
731- style = generate_css ({'stop-color' : rgb2hex (c ),
734+ style = generate_css ({'stop-color' : rgb2hex (rgba_color ),
732735 'stop-opacity' : "0" }))
733736
734737 writer .end ('linearGradient' )
0 commit comments