@@ -206,7 +206,7 @@ def draw_markers(self, gc, marker_path, marker_trans, path,
206206 def draw_path_collection (self , gc , master_transform , paths , all_transforms ,
207207 offsets , offset_trans , facecolors , edgecolors ,
208208 linewidths , linestyles , antialiaseds , urls ,
209- offset_position ):
209+ offset_position , hatchcolors = None ):
210210 """
211211 Draw a collection of *paths*.
212212
@@ -215,8 +215,8 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
215215 *master_transform*. They are then translated by the corresponding
216216 entry in *offsets*, which has been first transformed by *offset_trans*.
217217
218- *facecolors*, *edgecolors*, *linewidths*, *linestyles*, and
219- *antialiased * are lists that set the corresponding properties.
218+ *facecolors*, *edgecolors*, *linewidths*, *linestyles*, *antialiased*
219+ and *hatchcolors * are lists that set the corresponding properties.
220220
221221 *offset_position* is unused now, but the argument is kept for
222222 backwards compatibility.
@@ -233,10 +233,13 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
233233 path_ids = self ._iter_collection_raw_paths (master_transform ,
234234 paths , all_transforms )
235235
236+ if hatchcolors is None :
237+ hatchcolors = []
238+
236239 for xo , yo , path_id , gc0 , rgbFace in self ._iter_collection (
237240 gc , list (path_ids ), offsets , offset_trans ,
238241 facecolors , edgecolors , linewidths , linestyles ,
239- antialiaseds , urls , offset_position ):
242+ antialiaseds , urls , offset_position , hatchcolors ):
240243 path , transform = path_id
241244 # Only apply another translation if we have an offset, else we
242245 # reuse the initial transform.
@@ -250,7 +253,7 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
250253
251254 def draw_quad_mesh (self , gc , master_transform , meshWidth , meshHeight ,
252255 coordinates , offsets , offsetTrans , facecolors ,
253- antialiased , edgecolors ):
256+ antialiased , edgecolors , hatchcolors = None ):
254257 """
255258 Draw a quadmesh.
256259
@@ -263,11 +266,13 @@ def draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight,
263266
264267 if edgecolors is None :
265268 edgecolors = facecolors
269+ if hatchcolors is None :
270+ hatchcolors = []
266271 linewidths = np .array ([gc .get_linewidth ()], float )
267272
268273 return self .draw_path_collection (
269274 gc , master_transform , paths , [], offsets , offsetTrans , facecolors ,
270- edgecolors , linewidths , [], [antialiased ], [None ], 'screen' )
275+ edgecolors , linewidths , [], [antialiased ], [None ], 'screen' , hatchcolors )
271276
272277 def draw_gouraud_triangles (self , gc , triangles_array , colors_array ,
273278 transform ):
@@ -335,7 +340,7 @@ def _iter_collection_uses_per_path(self, paths, all_transforms,
335340
336341 def _iter_collection (self , gc , path_ids , offsets , offset_trans , facecolors ,
337342 edgecolors , linewidths , linestyles ,
338- antialiaseds , urls , offset_position ):
343+ antialiaseds , urls , offset_position , hatchcolors = None ):
339344 """
340345 Helper method (along with `_iter_collection_raw_paths`) to implement
341346 `draw_path_collection` in a memory-efficient manner.
@@ -358,16 +363,20 @@ def _iter_collection(self, gc, path_ids, offsets, offset_trans, facecolors,
358363 *path_ids*; *gc* is a graphics context and *rgbFace* is a color to
359364 use for filling the path.
360365 """
366+ if hatchcolors is None :
367+ hatchcolors = []
368+
361369 Npaths = len (path_ids )
362370 Noffsets = len (offsets )
363371 N = max (Npaths , Noffsets )
364372 Nfacecolors = len (facecolors )
365373 Nedgecolors = len (edgecolors )
374+ Nhatchcolors = len (hatchcolors )
366375 Nlinewidths = len (linewidths )
367376 Nlinestyles = len (linestyles )
368377 Nurls = len (urls )
369378
370- if (Nfacecolors == 0 and Nedgecolors == 0 ) or Npaths == 0 :
379+ if (Nfacecolors == 0 and Nedgecolors == 0 and Nhatchcolors == 0 ) or Npaths == 0 :
371380 return
372381
373382 gc0 = self .new_gc ()
@@ -382,6 +391,7 @@ def cycle_or_default(seq, default=None):
382391 toffsets = cycle_or_default (offset_trans .transform (offsets ), (0 , 0 ))
383392 fcs = cycle_or_default (facecolors )
384393 ecs = cycle_or_default (edgecolors )
394+ hcs = cycle_or_default (hatchcolors )
385395 lws = cycle_or_default (linewidths )
386396 lss = cycle_or_default (linestyles )
387397 aas = cycle_or_default (antialiaseds )
@@ -390,8 +400,8 @@ def cycle_or_default(seq, default=None):
390400 if Nedgecolors == 0 :
391401 gc0 .set_linewidth (0.0 )
392402
393- for pathid , (xo , yo ), fc , ec , lw , ls , aa , url in itertools .islice (
394- zip (pathids , toffsets , fcs , ecs , lws , lss , aas , urls ), N ):
403+ for pathid , (xo , yo ), fc , ec , hc , lw , ls , aa , url in itertools .islice (
404+ zip (pathids , toffsets , fcs , ecs , hcs , lws , lss , aas , urls ), N ):
395405 if not (np .isfinite (xo ) and np .isfinite (yo )):
396406 continue
397407 if Nedgecolors :
@@ -403,6 +413,8 @@ def cycle_or_default(seq, default=None):
403413 gc0 .set_linewidth (0 )
404414 else :
405415 gc0 .set_foreground (ec )
416+ if Nhatchcolors :
417+ gc0 .set_hatch_color (hc )
406418 if fc is not None and len (fc ) == 4 and fc [3 ] == 0 :
407419 fc = None
408420 gc0 .set_antialiased (aa )
@@ -690,7 +702,7 @@ def __init__(self):
690702 self ._linewidth = 1
691703 self ._rgb = (0.0 , 0.0 , 0.0 , 1.0 )
692704 self ._hatch = None
693- self ._hatch_color = colors . to_rgba ( rcParams [ 'hatch.color' ])
705+ self ._hatch_color = None
694706 self ._hatch_linewidth = rcParams ['hatch.linewidth' ]
695707 self ._url = None
696708 self ._gid = None
0 commit comments