@@ -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')
@@ -833,14 +836,19 @@ def get_snap(self):
833836
834837 def set_alpha (self , alpha ):
835838 """
836- Set the alpha value used for blending - not supported on
837- all backends
839+ Set the alpha value used for blending - not supported on all backends.
840+ If ``alpha=None`` (the default), the alpha components of the
841+ foreground and fill colors will be used to set their respective
842+ transparencies (where applicable); otherwise, ``alpha`` will override
843+ them.
838844 """
839845 if alpha is not None :
840846 self ._alpha = alpha
841847 self ._forced_alpha = True
842848 else :
849+ self ._alpha = 1.0
843850 self ._forced_alpha = False
851+ self .set_foreground (self ._orig_color )
844852
845853 def set_antialiased (self , b ):
846854 """
@@ -890,30 +898,28 @@ def set_dashes(self, dash_offset, dash_list):
890898 """
891899 self ._dashes = dash_offset , dash_list
892900
893- def set_foreground (self , fg , isRGB = False ):
901+ def set_foreground (self , fg , isRGBA = False ):
894902 """
895903 Set the foreground color. fg can be a MATLAB format string, a
896904 html hex color string, an rgb or rgba unit tuple, or a float between 0
897905 and 1. In the latter case, grayscale is used.
898906
899- If you know fg is rgb or rgba, set ``isRGB=True`` for
900- efficiency.
907+ If you know fg is rgba, set ``isRGBA=True`` for efficiency.
901908 """
902- if isRGB :
909+ self ._orig_color = fg
910+ if self ._forced_alpha :
911+ self ._rgb = colors .colorConverter .to_rgba (fg , self ._alpha )
912+ elif isRGBA :
903913 self ._rgb = fg
904914 else :
905915 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.
911916
912917 def set_graylevel (self , frac ):
913918 """
914919 Set the foreground color to be a gray level with *frac*
915920 """
916- self ._rgb = (frac , frac , frac )
921+ self ._orig_color = frac
922+ self ._rgb = (frac , frac , frac , self ._alpha )
917923
918924 def set_joinstyle (self , js ):
919925 """
@@ -942,7 +948,7 @@ def set_linestyle(self, style):
942948 'dotted' : (0, (1.0, 3.0)),
943949 """
944950
945- if style in self .dashd . keys () :
951+ if style in self .dashd :
946952 offset , dashes = self .dashd [style ]
947953 elif isinstance (style , tuple ):
948954 offset , dashes = style
0 commit comments