@@ -637,6 +637,7 @@ class GraphicsContextBase:
637
637
638
638
def __init__ (self ):
639
639
self ._alpha = 1.0
640
+ self ._forced_alpha = False # if True, _alpha overrides A from RGBA
640
641
self ._antialiased = 1 # use 0,1 not True, False for extension code
641
642
self ._capstyle = 'butt'
642
643
self ._cliprect = None
@@ -742,8 +743,7 @@ def get_linewidth(self):
742
743
743
744
def get_rgb (self ):
744
745
"""
745
- returns a tuple of three floats from 0-1. color can be a
746
- MATLAB format string, a html hex color string, or a rgb tuple
746
+ returns a tuple of three or four floats from 0-1.
747
747
"""
748
748
return self ._rgb
749
749
@@ -771,9 +771,9 @@ def set_alpha(self, alpha):
771
771
Set the alpha value used for blending - not supported on
772
772
all backends
773
773
"""
774
- if alpha is None :
775
- alpha = 1.0
776
- self ._alpha = alpha
774
+ if alpha is not None :
775
+ self . _alpha = alpha
776
+ self ._forced_alpha = True
777
777
778
778
def set_antialiased (self , b ):
779
779
"""
@@ -823,17 +823,18 @@ def set_dashes(self, dash_offset, dash_list):
823
823
def set_foreground (self , fg , isRGB = False ):
824
824
"""
825
825
Set the foreground color. fg can be a MATLAB format string, a
826
- html hex color string, an rgb unit tuple, or a float between 0
826
+ html hex color string, an rgb or rgba unit tuple, or a float between 0
827
827
and 1. In the latter case, grayscale is used.
828
828
829
- The :class:`GraphicsContextBase` converts colors to rgb
830
- internally. If you know the color is rgb already, you can set
831
- ``isRGB=True`` to avoid the performace hit of the conversion
829
+ If you know fg is rgb or rgba, set ``isRGB=True`` for
830
+ efficiency.
832
831
"""
833
832
if isRGB :
834
833
self ._rgb = fg
835
834
else :
836
835
self ._rgb = colors .colorConverter .to_rgba (fg )
836
+ if len (self ._rgb ) == 4 and not self ._forced_alpha :
837
+ self ._alpha = self ._rgb [3 ]
837
838
838
839
def set_graylevel (self , frac ):
839
840
"""
0 commit comments