@@ -362,8 +362,6 @@ def _iter_collection(self, gc, master_transform, all_transforms,
362362 gc0 = self .new_gc ()
363363 gc0 .copy_properties (gc )
364364
365- original_alpha = gc .get_alpha ()
366-
367365 if Nfacecolors == 0 :
368366 rgbFace = None
369367
@@ -387,7 +385,6 @@ def _iter_collection(self, gc, master_transform, all_transforms,
387385 yo = - (yp - yo )
388386 if not (np .isfinite (xo ) and np .isfinite (yo )):
389387 continue
390- gc0 .set_alpha (original_alpha )
391388 if Nfacecolors :
392389 rgbFace = facecolors [i % Nfacecolors ]
393390 if Nedgecolors :
@@ -400,16 +397,12 @@ def _iter_collection(self, gc, master_transform, all_transforms,
400397 if fg [3 ] == 0.0 :
401398 gc0 .set_linewidth (0 )
402399 else :
403- gc0 .set_alpha (gc0 .get_alpha () * fg [3 ])
404- gc0 .set_foreground (fg [:3 ])
400+ gc0 .set_foreground (fg )
405401 else :
406402 gc0 .set_foreground (fg )
407403 if rgbFace is not None and len (rgbFace ) == 4 :
408404 if rgbFace [3 ] == 0 :
409405 rgbFace = None
410- else :
411- gc0 .set_alpha (gc0 .get_alpha () * rgbFace [3 ])
412- rgbFace = rgbFace [:3 ]
413406 gc0 .set_antialiased (antialiaseds [i % Naa ])
414407 if Nurls :
415408 gc0 .set_url (urls [i % Nurls ])
@@ -562,7 +555,7 @@ def _draw_text_as_path(self, gc, x, y, s, prop, angle, ismath):
562555
563556 path , transform = self ._get_text_path_transform (
564557 x , y , s , prop , angle , ismath )
565- color = gc .get_rgb ()[: 3 ]
558+ color = gc .get_rgb ()
566559
567560 gc .set_linewidth (0.0 )
568561 self .draw_path (gc , path , transform , rgbFace = color )
@@ -702,7 +695,8 @@ def __init__(self):
702695 self ._joinstyle = 'round'
703696 self ._linestyle = 'solid'
704697 self ._linewidth = 1
705- self ._rgb = (0.0 , 0.0 , 0.0 )
698+ self ._rgb = (0.0 , 0.0 , 0.0 , 1.0 )
699+ self ._orig_color = (0.0 , 0.0 , 0.0 , 1.0 )
706700 self ._hatch = None
707701 self ._url = None
708702 self ._gid = None
@@ -711,6 +705,7 @@ def __init__(self):
711705 def copy_properties (self , gc ):
712706 'Copy properties from gc to self'
713707 self ._alpha = gc ._alpha
708+ self ._forced_alpha = gc ._forced_alpha
714709 self ._antialiased = gc ._antialiased
715710 self ._capstyle = gc ._capstyle
716711 self ._cliprect = gc ._cliprect
@@ -720,6 +715,7 @@ def copy_properties(self, gc):
720715 self ._linestyle = gc ._linestyle
721716 self ._linewidth = gc ._linewidth
722717 self ._rgb = gc ._rgb
718+ self ._orig_color = gc ._orig_color
723719 self ._hatch = gc ._hatch
724720 self ._url = gc ._url
725721 self ._gid = gc ._gid
@@ -781,6 +777,13 @@ def get_dashes(self):
781777 """
782778 return self ._dashes
783779
780+ def get_forced_alpha (self ):
781+ """
782+ Return whether the value given by get_alpha() should be used to
783+ override any other alpha-channel values.
784+ """
785+ return self ._forced_alpha
786+
784787 def get_joinstyle (self ):
785788 """
786789 Return the line join style as one of ('miter', 'round', 'bevel')
@@ -840,7 +843,9 @@ def set_alpha(self, alpha):
840843 self ._alpha = alpha
841844 self ._forced_alpha = True
842845 else :
846+ self ._alpha = 1.0
843847 self ._forced_alpha = False
848+ self .set_foreground (self ._orig_color )
844849
845850 def set_antialiased (self , b ):
846851 """
@@ -890,30 +895,29 @@ def set_dashes(self, dash_offset, dash_list):
890895 """
891896 self ._dashes = dash_offset , dash_list
892897
893- def set_foreground (self , fg , isRGB = False ):
898+ def set_foreground (self , fg , isRGBA = False ):
894899 """
895900 Set the foreground color. fg can be a MATLAB format string, a
896901 html hex color string, an rgb or rgba unit tuple, or a float between 0
897902 and 1. In the latter case, grayscale is used.
898903
899- If you know fg is rgb or rgba, set ``isRGB =True`` for
904+ If you know fg is rgb or rgba, set ``isRGBA =True`` for
900905 efficiency.
901906 """
902- if isRGB :
907+ self ._orig_color = fg
908+ if self ._forced_alpha :
909+ self ._rgb = colors .colorConverter .to_rgba (fg , self ._alpha )
910+ elif isRGBA :
903911 self ._rgb = fg
904912 else :
905913 self ._rgb = colors .colorConverter .to_rgba (fg )
906- if len (self ._rgb ) == 4 and not self ._forced_alpha :
907- self .set_alpha (self ._rgb [3 ])
908- # Use set_alpha method here so that subclasses will
909- # be calling their own version, which may set their
910- # own attributes.
911914
912915 def set_graylevel (self , frac ):
913916 """
914917 Set the foreground color to be a gray level with *frac*
915918 """
916- self ._rgb = (frac , frac , frac )
919+ self ._orig_color = frac
920+ self ._rgb = (frac , frac , frac , self ._alpha )
917921
918922 def set_joinstyle (self , js ):
919923 """
0 commit comments