@@ -55,6 +55,7 @@ def __str__(self):
5555 def __init__ (self ,
5656 edgecolor = None ,
5757 facecolor = None ,
58+ color = None ,
5859 linewidth = None ,
5960 linestyle = None ,
6061 antialiased = None ,
@@ -74,20 +75,22 @@ def __init__(self,
7475 if linestyle is None : linestyle = "solid"
7576 if antialiased is None : antialiased = mpl .rcParams ['patch.antialiased' ]
7677
77- if 'color' in kwargs :
78+ self ._fill = True # needed for set_facecolor call
79+ if color is not None :
7880 if (edgecolor is not None or
7981 facecolor is not None ):
8082 import warnings
8183 warnings .warn ("Setting the 'color' property will override"
8284 "the edgecolor or facecolor properties. " )
83-
84- self .set_edgecolor (edgecolor )
85- self .set_facecolor (facecolor )
85+ self .set_color (color )
86+ else :
87+ self .set_edgecolor (edgecolor )
88+ self .set_facecolor (facecolor )
8689 self .set_linewidth (linewidth )
8790 self .set_linestyle (linestyle )
8891 self .set_antialiased (antialiased )
8992 self .set_hatch (hatch )
90- self .fill = fill
93+ self .set_fill ( fill )
9194 self ._combined_transform = transforms .IdentityTransform ()
9295
9396 self .set_path_effects (path_effects )
@@ -98,7 +101,7 @@ def get_verts(self):
98101 """
99102 Return a copy of the vertices used in this patch
100103
101- If the patch contains Bézier curves, the curves will be
104+ If the patch contains Bezier curves, the curves will be
102105 interpolated by line segments. To access the curves as
103106 curves, use :meth:`get_path`.
104107 """
@@ -223,7 +226,7 @@ def set_edgecolor(self, color):
223226 ACCEPTS: mpl color spec, or None for default, or 'none' for no color
224227 """
225228 if color is None : color = mpl .rcParams ['patch.edgecolor' ]
226- self ._edgecolor = color
229+ self ._edgecolor = colors . colorConverter . to_rgba ( color , self . _alpha )
227230
228231 def set_ec (self , color ):
229232 """alias for set_edgecolor"""
@@ -236,7 +239,12 @@ def set_facecolor(self, color):
236239 ACCEPTS: mpl color spec, or None for default, or 'none' for no color
237240 """
238241 if color is None : color = mpl .rcParams ['patch.facecolor' ]
239- self ._facecolor = color
242+ self ._original_facecolor = color # save: otherwise changing _fill
243+ # may lose alpha information
244+ self ._facecolor = colors .colorConverter .to_rgba (color , self ._alpha )
245+ if not self ._fill :
246+ self ._facecolor = list (self ._facecolor )
247+ self ._facecolor [3 ] = 0
240248
241249 def set_fc (self , color ):
242250 """alias for set_facecolor"""
@@ -256,6 +264,21 @@ def set_color(self, c):
256264 self .set_facecolor (c )
257265 self .set_edgecolor (c )
258266
267+ def set_alpha (self , alpha ):
268+ """
269+ Set the alpha tranparency of the patch.
270+
271+ ACCEPTS: float or None
272+ """
273+ if alpha is not None :
274+ try :
275+ float (alpha )
276+ except TypeError :
277+ raise TypeError ('alpha must be a float or None' )
278+ artist .Artist .set_alpha (self , alpha )
279+ self .set_facecolor (self ._original_facecolor ) # using self._fill and self._alpha
280+ self ._edgecolor = colors .colorConverter .to_rgba (
281+ self ._edgecolor [:3 ], self ._alpha )
259282
260283 def set_linewidth (self , w ):
261284 """
@@ -289,11 +312,12 @@ def set_fill(self, b):
289312
290313 ACCEPTS: [True | False]
291314 """
292- self .fill = b
315+ self ._fill = b
316+ self .set_facecolor (self ._original_facecolor )
293317
294318 def get_fill (self ):
295319 'return whether fill is set'
296- return self .fill
320+ return self ._fill
297321
298322 def set_hatch (self , hatch ):
299323 """
@@ -345,28 +369,24 @@ def draw(self, renderer):
345369 renderer .open_group ('patch' , self .get_gid ())
346370 gc = renderer .new_gc ()
347371
348- if cbook .is_string_like (self ._edgecolor ) and self ._edgecolor .lower ()== 'none' :
349- gc .set_linewidth (0 )
350- else :
351- gc .set_foreground (self ._edgecolor )
352- gc .set_linewidth (self ._linewidth )
353- gc .set_linestyle (self ._linestyle )
372+ gc .set_alpha (self ._edgecolor [3 ])
373+ gc .set_foreground (self ._edgecolor , isRGB = True )
374+
375+ lw = self ._linewidth
376+ if self ._edgecolor [3 ] == 0 :
377+ lw = 0
378+ gc .set_linewidth (lw )
379+ gc .set_linestyle (self ._linestyle )
354380
355381 gc .set_antialiased (self ._antialiased )
356382 self ._set_gc_clip (gc )
357383 gc .set_capstyle ('projecting' )
358384 gc .set_url (self ._url )
359385 gc .set_snap (self .get_snap ())
360386
361- if (not self .fill or self ._facecolor is None or
362- (cbook .is_string_like (self ._facecolor ) and self ._facecolor .lower ()== 'none' )):
363- rgbFace = None
364- gc .set_alpha (1.0 )
365- else :
366- r , g , b , a = colors .colorConverter .to_rgba (self ._facecolor , self ._alpha )
367- rgbFace = (r , g , b )
368- gc .set_alpha (a )
369-
387+ rgbFace = self ._facecolor
388+ if rgbFace [3 ] == 0 :
389+ rgbFace = None # (some?) renderers expect this as no-fill signal
370390
371391 if self ._hatch :
372392 gc .set_hatch (self ._hatch )
@@ -3823,39 +3843,35 @@ def get_path_in_displaycoord(self):
38233843 )
38243844
38253845 #if not fillable:
3826- # self.fill = False
3846+ # self._fill = False
38273847
38283848 return _path , fillable
38293849
38303850
38313851
38323852 def draw (self , renderer ):
38333853 if not self .get_visible (): return
3834- #renderer.open_group('patch')
3854+
3855+ renderer .open_group ('patch' , self .get_gid ())
38353856 gc = renderer .new_gc ()
38363857
3858+ gc .set_alpha (self ._edgecolor [3 ])
3859+ gc .set_foreground (self ._edgecolor , isRGB = True )
38373860
3838- if cbook .is_string_like (self ._edgecolor ) and self ._edgecolor .lower ()== 'none' :
3839- gc .set_linewidth (0 )
3840- else :
3841- gc .set_foreground (self ._edgecolor )
3842- gc .set_linewidth (self ._linewidth )
3843- gc .set_linestyle (self ._linestyle )
3861+ lw = self ._linewidth
3862+ if self ._edgecolor [3 ] == 0 :
3863+ lw = 0
3864+ gc .set_linewidth (lw )
3865+ gc .set_linestyle (self ._linestyle )
38443866
38453867 gc .set_antialiased (self ._antialiased )
38463868 self ._set_gc_clip (gc )
38473869 gc .set_capstyle ('round' )
38483870 gc .set_snap (self .get_snap ())
38493871
3850- if (not self .fill or self ._facecolor is None or
3851- (cbook .is_string_like (self ._facecolor ) and self ._facecolor .lower ()== 'none' )):
3852- rgbFace = None
3853- gc .set_alpha (1.0 )
3854- else :
3855- r , g , b , a = colors .colorConverter .to_rgba (self ._facecolor , self ._alpha )
3856- rgbFace = (r , g , b )
3857- gc .set_alpha (a )
3858-
3872+ rgbFace = self ._facecolor
3873+ if rgbFace [3 ] == 0 :
3874+ rgbFace = None # (some?) renderers expect this as no-fill signal
38593875
38603876 if self ._hatch :
38613877 gc .set_hatch (self ._hatch )
@@ -3870,7 +3886,6 @@ def draw(self, renderer):
38703886
38713887 affine = transforms .IdentityTransform ()
38723888
3873- renderer .open_group ('patch' , self .get_gid ())
38743889
38753890 if self .get_path_effects ():
38763891 for path_effect in self .get_path_effects ():
0 commit comments