@@ -68,7 +68,6 @@ def __init__(self,
68
68
if antialiased is None :
69
69
antialiased = mpl .rcParams ['patch.antialiased' ]
70
70
71
- self ._hatch_color = colors .to_rgba (mpl .rcParams ['hatch.color' ])
72
71
self ._fill = True # needed for set_facecolor call
73
72
if color is not None :
74
73
if edgecolor is not None or facecolor is not None :
@@ -87,6 +86,7 @@ def __init__(self,
87
86
self .set_linewidth (linewidth )
88
87
self .set_antialiased (antialiased )
89
88
self .set_hatch (hatch )
89
+ self ._orig_hatch_color = colors .to_rgba (mpl .rcParams ['hatch.color' ])
90
90
self .set_capstyle (capstyle )
91
91
self .set_joinstyle (joinstyle )
92
92
self ._combined_transform = transforms .IdentityTransform ()
@@ -115,7 +115,7 @@ def _process_radius(self, radius):
115
115
if isinstance (self ._picker , Number ):
116
116
_radius = self ._picker
117
117
else :
118
- if self .get_edgecolor ()[3 ] == 0 :
118
+ if self ._get_drawn_edgecolor ()[3 ] == 0 :
119
119
_radius = 0
120
120
else :
121
121
_radius = self .get_linewidth ()
@@ -170,7 +170,6 @@ def update_from(self, other):
170
170
self ._facecolor = other ._facecolor
171
171
self ._fill = other ._fill
172
172
self ._hatch = other ._hatch
173
- self ._hatch_color = other ._hatch_color
174
173
# copy the unscaled dash pattern
175
174
self ._us_dashes = other ._us_dashes
176
175
self .set_linewidth (other ._linewidth ) # also sets dash properties
@@ -221,13 +220,23 @@ def get_edgecolor(self):
221
220
"""
222
221
Return the edge color of the :class:`Patch`.
223
222
"""
224
- return self ._edgecolor
223
+ ec = self ._edgecolor
224
+ if ec is None :
225
+ if (mpl .rcParams ['patch.force_edgecolor' ] or
226
+ not self ._fill or self ._edge_default ):
227
+ ec = mpl .rcParams ['patch.edgecolor' ]
228
+ else :
229
+ ec = 'none'
230
+ return ec
225
231
226
232
def get_facecolor (self ):
227
233
"""
228
234
Return the face color of the :class:`Patch`.
229
235
"""
230
- return self ._facecolor
236
+ fc = self ._facecolor
237
+ if fc is None :
238
+ fc = mpl .rcParams ['patch.facecolor' ]
239
+ return fc
231
240
232
241
def get_linewidth (self ):
233
242
"""
@@ -254,21 +263,6 @@ def set_antialiased(self, aa):
254
263
self ._antialiased = aa
255
264
self .stale = True
256
265
257
- def _set_edgecolor (self , color ):
258
- set_hatch_color = True
259
- if color is None :
260
- if (mpl .rcParams ['patch.force_edgecolor' ] or
261
- not self ._fill or self ._edge_default ):
262
- color = mpl .rcParams ['patch.edgecolor' ]
263
- else :
264
- color = 'none'
265
- set_hatch_color = False
266
-
267
- self ._edgecolor = colors .to_rgba (color , self ._alpha )
268
- if set_hatch_color :
269
- self ._hatch_color = self ._edgecolor
270
- self .stale = True
271
-
272
266
def set_edgecolor (self , color ):
273
267
"""
274
268
Set the patch edge color.
@@ -277,14 +271,7 @@ def set_edgecolor(self, color):
277
271
----------
278
272
color : color or None or 'auto'
279
273
"""
280
- self ._original_edgecolor = color
281
- self ._set_edgecolor (color )
282
-
283
- def _set_facecolor (self , color ):
284
- if color is None :
285
- color = mpl .rcParams ['patch.facecolor' ]
286
- alpha = self ._alpha if self ._fill else 0
287
- self ._facecolor = colors .to_rgba (color , alpha )
274
+ self ._edgecolor = color
288
275
self .stale = True
289
276
290
277
def set_facecolor (self , color ):
@@ -295,8 +282,8 @@ def set_facecolor(self, color):
295
282
----------
296
283
color : color or None
297
284
"""
298
- self ._original_facecolor = color
299
- self ._set_facecolor ( color )
285
+ self ._facecolor = color
286
+ self .stale = True
300
287
301
288
def set_color (self , c ):
302
289
"""
@@ -314,24 +301,6 @@ def set_color(self, c):
314
301
self .set_facecolor (c )
315
302
self .set_edgecolor (c )
316
303
317
- def set_alpha (self , alpha ):
318
- """
319
- Set the alpha transparency of the patch.
320
-
321
- Parameters
322
- ----------
323
- alpha : float or None
324
- """
325
- if alpha is not None :
326
- try :
327
- float (alpha )
328
- except TypeError :
329
- raise TypeError ('alpha must be a float or None' )
330
- artist .Artist .set_alpha (self , alpha )
331
- self ._set_facecolor (self ._original_facecolor )
332
- self ._set_edgecolor (self ._original_edgecolor )
333
- # stale is already True
334
-
335
304
def set_linewidth (self , w ):
336
305
"""
337
306
Set the patch linewidth in points
@@ -393,8 +362,7 @@ def set_fill(self, b):
393
362
b : bool
394
363
"""
395
364
self ._fill = bool (b )
396
- self ._set_facecolor (self ._original_facecolor )
397
- self ._set_edgecolor (self ._original_edgecolor )
365
+ self .set_edgecolor (self ._edgecolor )
398
366
self .stale = True
399
367
400
368
def get_fill (self ):
@@ -479,6 +447,24 @@ def get_hatch(self):
479
447
'Return the current hatching pattern'
480
448
return self ._hatch
481
449
450
+ def _get_drawn_edgecolor (self ):
451
+ return colors .to_rgba (self .get_edgecolor (), self ._alpha )
452
+
453
+ def _get_drawn_facecolor (self ):
454
+ return colors .to_rgba (self .get_facecolor (),
455
+ self ._alpha if self ._fill else 0 )
456
+
457
+ def _get_drawn_hatchcolor (self ):
458
+ hc = self ._edgecolor
459
+ if hc is None :
460
+ if (mpl .rcParams ['patch.force_edgecolor' ] or
461
+ not self ._fill or self ._edge_default ):
462
+ hc = mpl .rcParams ['patch.edgecolor' ]
463
+ else :
464
+ # Not affected by alpha.
465
+ return self ._orig_hatch_color
466
+ return colors .to_rgba (hc , self ._alpha )
467
+
482
468
@artist .allow_rasterization
483
469
def draw (self , renderer ):
484
470
'Draw the :class:`Patch` to the given *renderer*.'
@@ -488,10 +474,11 @@ def draw(self, renderer):
488
474
renderer .open_group ('patch' , self .get_gid ())
489
475
gc = renderer .new_gc ()
490
476
491
- gc .set_foreground (self ._edgecolor , isRGBA = True )
477
+ edgecolor = self ._get_drawn_edgecolor ()
478
+ gc .set_foreground (edgecolor , isRGBA = True )
492
479
493
480
lw = self ._linewidth
494
- if self . _edgecolor [3 ] == 0 :
481
+ if edgecolor [3 ] == 0 :
495
482
lw = 0
496
483
gc .set_linewidth (lw )
497
484
gc .set_dashes (0 , self ._dashes )
@@ -503,7 +490,7 @@ def draw(self, renderer):
503
490
gc .set_url (self ._url )
504
491
gc .set_snap (self .get_snap ())
505
492
506
- rgbFace = self ._facecolor
493
+ rgbFace = self ._get_drawn_facecolor ()
507
494
if rgbFace [3 ] == 0 :
508
495
rgbFace = None # (some?) renderers expect this as no-fill signal
509
496
@@ -512,7 +499,7 @@ def draw(self, renderer):
512
499
if self ._hatch :
513
500
gc .set_hatch (self ._hatch )
514
501
try :
515
- gc .set_hatch_color (self ._hatch_color )
502
+ gc .set_hatch_color (self ._get_drawn_hatchcolor () )
516
503
except AttributeError :
517
504
# if we end up with a GC that does not have this method
518
505
warnings .warn (
@@ -4259,10 +4246,11 @@ def draw(self, renderer):
4259
4246
renderer .open_group ('patch' , self .get_gid ())
4260
4247
gc = renderer .new_gc ()
4261
4248
4262
- gc .set_foreground (self ._edgecolor , isRGBA = True )
4249
+ edgecolor = self ._get_drawn_edgecolor ()
4250
+ gc .set_foreground (edgecolor , isRGBA = True )
4263
4251
4264
4252
lw = self ._linewidth
4265
- if self . _edgecolor [3 ] == 0 :
4253
+ if edgecolor [3 ] == 0 :
4266
4254
lw = 0
4267
4255
gc .set_linewidth (lw )
4268
4256
gc .set_dashes (self ._dashoffset , self ._dashes )
@@ -4272,7 +4260,7 @@ def draw(self, renderer):
4272
4260
gc .set_capstyle ('round' )
4273
4261
gc .set_snap (self .get_snap ())
4274
4262
4275
- rgbFace = self ._facecolor
4263
+ rgbFace = self ._get_drawn_facecolor ()
4276
4264
if rgbFace [3 ] == 0 :
4277
4265
rgbFace = None # (some?) renderers expect this as no-fill signal
4278
4266
@@ -4282,7 +4270,7 @@ def draw(self, renderer):
4282
4270
gc .set_hatch (self ._hatch )
4283
4271
if self ._hatch_color is not None :
4284
4272
try :
4285
- gc .set_hatch_color (self ._hatch_color )
4273
+ gc .set_hatch_color (self ._get_drawn_hatchcolor () )
4286
4274
except AttributeError :
4287
4275
# if we end up with a GC that does not have this method
4288
4276
warnings .warn ("Your backend does not support setting the "
0 commit comments