@@ -208,7 +208,7 @@ def draw_markers(self, gc, marker_path, marker_trans, path,
208208 def draw_path_collection (self , gc , master_transform , paths , all_transforms ,
209209 offsets , offset_trans , facecolors , edgecolors ,
210210 linewidths , linestyles , antialiaseds , urls ,
211- offset_position ):
211+ offset_position , * , hatchcolors = None ):
212212 """
213213 Draw a collection of *paths*.
214214
@@ -217,8 +217,11 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
217217 *master_transform*. They are then translated by the corresponding
218218 entry in *offsets*, which has been first transformed by *offset_trans*.
219219
220- *facecolors*, *edgecolors*, *linewidths*, *linestyles*, and
221- *antialiased* are lists that set the corresponding properties.
220+ *facecolors*, *edgecolors*, *linewidths*, *linestyles*, *antialiased*
221+ and *hatchcolors* are lists that set the corresponding properties.
222+
223+ .. versionadded:: 3.11
224+ Allow *hatchcolors* to be specified.
222225
223226 *offset_position* is unused now, but the argument is kept for
224227 backwards compatibility.
@@ -235,10 +238,13 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
235238 path_ids = self ._iter_collection_raw_paths (master_transform ,
236239 paths , all_transforms )
237240
241+ if hatchcolors is None :
242+ hatchcolors = []
243+
238244 for xo , yo , path_id , gc0 , rgbFace in self ._iter_collection (
239245 gc , list (path_ids ), offsets , offset_trans ,
240246 facecolors , edgecolors , linewidths , linestyles ,
241- antialiaseds , urls , offset_position ):
247+ antialiaseds , urls , offset_position , hatchcolors = hatchcolors ):
242248 path , transform = path_id
243249 # Only apply another translation if we have an offset, else we
244250 # reuse the initial transform.
@@ -252,7 +258,7 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
252258
253259 def draw_quad_mesh (self , gc , master_transform , meshWidth , meshHeight ,
254260 coordinates , offsets , offsetTrans , facecolors ,
255- antialiased , edgecolors ):
261+ antialiased , edgecolors , * , hatchcolors = None ):
256262 """
257263 Draw a quadmesh.
258264
@@ -265,11 +271,14 @@ def draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight,
265271
266272 if edgecolors is None :
267273 edgecolors = facecolors
274+ if hatchcolors is None :
275+ hatchcolors = []
268276 linewidths = np .array ([gc .get_linewidth ()], float )
269277
270278 return self .draw_path_collection (
271279 gc , master_transform , paths , [], offsets , offsetTrans , facecolors ,
272- edgecolors , linewidths , [], [antialiased ], [None ], 'screen' )
280+ edgecolors , linewidths , [], [antialiased ], [None ], 'screen' ,
281+ hatchcolors = hatchcolors )
273282
274283 def draw_gouraud_triangles (self , gc , triangles_array , colors_array ,
275284 transform ):
@@ -337,7 +346,7 @@ def _iter_collection_uses_per_path(self, paths, all_transforms,
337346
338347 def _iter_collection (self , gc , path_ids , offsets , offset_trans , facecolors ,
339348 edgecolors , linewidths , linestyles ,
340- antialiaseds , urls , offset_position ):
349+ antialiaseds , urls , offset_position , * , hatchcolors ):
341350 """
342351 Helper method (along with `_iter_collection_raw_paths`) to implement
343352 `draw_path_collection` in a memory-efficient manner.
@@ -365,11 +374,12 @@ def _iter_collection(self, gc, path_ids, offsets, offset_trans, facecolors,
365374 N = max (Npaths , Noffsets )
366375 Nfacecolors = len (facecolors )
367376 Nedgecolors = len (edgecolors )
377+ Nhatchcolors = len (hatchcolors )
368378 Nlinewidths = len (linewidths )
369379 Nlinestyles = len (linestyles )
370380 Nurls = len (urls )
371381
372- if (Nfacecolors == 0 and Nedgecolors == 0 ) or Npaths == 0 :
382+ if (Nfacecolors == 0 and Nedgecolors == 0 and Nhatchcolors == 0 ) or Npaths == 0 :
373383 return
374384
375385 gc0 = self .new_gc ()
@@ -384,6 +394,7 @@ def cycle_or_default(seq, default=None):
384394 toffsets = cycle_or_default (offset_trans .transform (offsets ), (0 , 0 ))
385395 fcs = cycle_or_default (facecolors )
386396 ecs = cycle_or_default (edgecolors )
397+ hcs = cycle_or_default (hatchcolors )
387398 lws = cycle_or_default (linewidths )
388399 lss = cycle_or_default (linestyles )
389400 aas = cycle_or_default (antialiaseds )
@@ -392,8 +403,8 @@ def cycle_or_default(seq, default=None):
392403 if Nedgecolors == 0 :
393404 gc0 .set_linewidth (0.0 )
394405
395- for pathid , (xo , yo ), fc , ec , lw , ls , aa , url in itertools .islice (
396- zip (pathids , toffsets , fcs , ecs , lws , lss , aas , urls ), N ):
406+ for pathid , (xo , yo ), fc , ec , hc , lw , ls , aa , url in itertools .islice (
407+ zip (pathids , toffsets , fcs , ecs , hcs , lws , lss , aas , urls ), N ):
397408 if not (np .isfinite (xo ) and np .isfinite (yo )):
398409 continue
399410 if Nedgecolors :
@@ -405,6 +416,8 @@ def cycle_or_default(seq, default=None):
405416 gc0 .set_linewidth (0 )
406417 else :
407418 gc0 .set_foreground (ec )
419+ if Nhatchcolors :
420+ gc0 .set_hatch_color (hc )
408421 if fc is not None and len (fc ) == 4 and fc [3 ] == 0 :
409422 fc = None
410423 gc0 .set_antialiased (aa )
0 commit comments