@@ -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,8 @@ 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.
222222
223223 *offset_position* is unused now, but the argument is kept for
224224 backwards compatibility.
@@ -235,10 +235,13 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
235235 path_ids = self ._iter_collection_raw_paths (master_transform ,
236236 paths , all_transforms )
237237
238+ if hatchcolors is None :
239+ hatchcolors = []
240+
238241 for xo , yo , path_id , gc0 , rgbFace in self ._iter_collection (
239242 gc , list (path_ids ), offsets , offset_trans ,
240243 facecolors , edgecolors , linewidths , linestyles ,
241- antialiaseds , urls , offset_position ):
244+ antialiaseds , urls , offset_position , hatchcolors ):
242245 path , transform = path_id
243246 # Only apply another translation if we have an offset, else we
244247 # reuse the initial transform.
@@ -252,7 +255,7 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
252255
253256 def draw_quad_mesh (self , gc , master_transform , meshWidth , meshHeight ,
254257 coordinates , offsets , offsetTrans , facecolors ,
255- antialiased , edgecolors ):
258+ antialiased , edgecolors , hatchcolors = None ):
256259 """
257260 Draw a quadmesh.
258261
@@ -265,11 +268,13 @@ def draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight,
265268
266269 if edgecolors is None :
267270 edgecolors = facecolors
271+ if hatchcolors is None :
272+ hatchcolors = []
268273 linewidths = np .array ([gc .get_linewidth ()], float )
269274
270275 return self .draw_path_collection (
271276 gc , master_transform , paths , [], offsets , offsetTrans , facecolors ,
272- edgecolors , linewidths , [], [antialiased ], [None ], 'screen' )
277+ edgecolors , linewidths , [], [antialiased ], [None ], 'screen' , hatchcolors )
273278
274279 def draw_gouraud_triangles (self , gc , triangles_array , colors_array ,
275280 transform ):
@@ -337,7 +342,7 @@ def _iter_collection_uses_per_path(self, paths, all_transforms,
337342
338343 def _iter_collection (self , gc , path_ids , offsets , offset_trans , facecolors ,
339344 edgecolors , linewidths , linestyles ,
340- antialiaseds , urls , offset_position ):
345+ antialiaseds , urls , offset_position , hatchcolors = None ):
341346 """
342347 Helper method (along with `_iter_collection_raw_paths`) to implement
343348 `draw_path_collection` in a memory-efficient manner.
@@ -360,16 +365,20 @@ def _iter_collection(self, gc, path_ids, offsets, offset_trans, facecolors,
360365 *path_ids*; *gc* is a graphics context and *rgbFace* is a color to
361366 use for filling the path.
362367 """
368+ if hatchcolors is None :
369+ hatchcolors = []
370+
363371 Npaths = len (path_ids )
364372 Noffsets = len (offsets )
365373 N = max (Npaths , Noffsets )
366374 Nfacecolors = len (facecolors )
367375 Nedgecolors = len (edgecolors )
376+ Nhatchcolors = len (hatchcolors )
368377 Nlinewidths = len (linewidths )
369378 Nlinestyles = len (linestyles )
370379 Nurls = len (urls )
371380
372- if (Nfacecolors == 0 and Nedgecolors == 0 ) or Npaths == 0 :
381+ if (Nfacecolors == 0 and Nedgecolors == 0 and Nhatchcolors == 0 ) or Npaths == 0 :
373382 return
374383
375384 gc0 = self .new_gc ()
@@ -384,6 +393,7 @@ def cycle_or_default(seq, default=None):
384393 toffsets = cycle_or_default (offset_trans .transform (offsets ), (0 , 0 ))
385394 fcs = cycle_or_default (facecolors )
386395 ecs = cycle_or_default (edgecolors )
396+ hcs = cycle_or_default (hatchcolors )
387397 lws = cycle_or_default (linewidths )
388398 lss = cycle_or_default (linestyles )
389399 aas = cycle_or_default (antialiaseds )
@@ -392,8 +402,8 @@ def cycle_or_default(seq, default=None):
392402 if Nedgecolors == 0 :
393403 gc0 .set_linewidth (0.0 )
394404
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 ):
405+ for pathid , (xo , yo ), fc , ec , hc , lw , ls , aa , url in itertools .islice (
406+ zip (pathids , toffsets , fcs , ecs , hcs , lws , lss , aas , urls ), N ):
397407 if not (np .isfinite (xo ) and np .isfinite (yo )):
398408 continue
399409 if Nedgecolors :
@@ -405,6 +415,8 @@ def cycle_or_default(seq, default=None):
405415 gc0 .set_linewidth (0 )
406416 else :
407417 gc0 .set_foreground (ec )
418+ if Nhatchcolors :
419+ gc0 .set_hatch_color (hc )
408420 if fc is not None and len (fc ) == 4 and fc [3 ] == 0 :
409421 fc = None
410422 gc0 .set_antialiased (aa )
0 commit comments