@@ -208,7 +208,7 @@ def draw_markers(self, gc, marker_path, marker_trans, path,
208
208
def draw_path_collection (self , gc , master_transform , paths , all_transforms ,
209
209
offsets , offset_trans , facecolors , edgecolors ,
210
210
linewidths , linestyles , antialiaseds , urls ,
211
- offset_position ):
211
+ offset_position , * , hatchcolors = None ):
212
212
"""
213
213
Draw a collection of *paths*.
214
214
@@ -217,8 +217,11 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
217
217
*master_transform*. They are then translated by the corresponding
218
218
entry in *offsets*, which has been first transformed by *offset_trans*.
219
219
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.
222
225
223
226
*offset_position* is unused now, but the argument is kept for
224
227
backwards compatibility.
@@ -235,10 +238,13 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
235
238
path_ids = self ._iter_collection_raw_paths (master_transform ,
236
239
paths , all_transforms )
237
240
241
+ if hatchcolors is None :
242
+ hatchcolors = []
243
+
238
244
for xo , yo , path_id , gc0 , rgbFace in self ._iter_collection (
239
245
gc , list (path_ids ), offsets , offset_trans ,
240
246
facecolors , edgecolors , linewidths , linestyles ,
241
- antialiaseds , urls , offset_position ):
247
+ antialiaseds , urls , offset_position , hatchcolors = hatchcolors ):
242
248
path , transform = path_id
243
249
# Only apply another translation if we have an offset, else we
244
250
# reuse the initial transform.
@@ -252,7 +258,7 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
252
258
253
259
def draw_quad_mesh (self , gc , master_transform , meshWidth , meshHeight ,
254
260
coordinates , offsets , offsetTrans , facecolors ,
255
- antialiased , edgecolors ):
261
+ antialiased , edgecolors , * , hatchcolors = None ):
256
262
"""
257
263
Draw a quadmesh.
258
264
@@ -265,11 +271,14 @@ def draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight,
265
271
266
272
if edgecolors is None :
267
273
edgecolors = facecolors
274
+ if hatchcolors is None :
275
+ hatchcolors = []
268
276
linewidths = np .array ([gc .get_linewidth ()], float )
269
277
270
278
return self .draw_path_collection (
271
279
gc , master_transform , paths , [], offsets , offsetTrans , facecolors ,
272
- edgecolors , linewidths , [], [antialiased ], [None ], 'screen' )
280
+ edgecolors , linewidths , [], [antialiased ], [None ], 'screen' ,
281
+ hatchcolors = hatchcolors )
273
282
274
283
def draw_gouraud_triangles (self , gc , triangles_array , colors_array ,
275
284
transform ):
@@ -337,7 +346,7 @@ def _iter_collection_uses_per_path(self, paths, all_transforms,
337
346
338
347
def _iter_collection (self , gc , path_ids , offsets , offset_trans , facecolors ,
339
348
edgecolors , linewidths , linestyles ,
340
- antialiaseds , urls , offset_position ):
349
+ antialiaseds , urls , offset_position , * , hatchcolors ):
341
350
"""
342
351
Helper method (along with `_iter_collection_raw_paths`) to implement
343
352
`draw_path_collection` in a memory-efficient manner.
@@ -365,11 +374,12 @@ def _iter_collection(self, gc, path_ids, offsets, offset_trans, facecolors,
365
374
N = max (Npaths , Noffsets )
366
375
Nfacecolors = len (facecolors )
367
376
Nedgecolors = len (edgecolors )
377
+ Nhatchcolors = len (hatchcolors )
368
378
Nlinewidths = len (linewidths )
369
379
Nlinestyles = len (linestyles )
370
380
Nurls = len (urls )
371
381
372
- if (Nfacecolors == 0 and Nedgecolors == 0 ) or Npaths == 0 :
382
+ if (Nfacecolors == 0 and Nedgecolors == 0 and Nhatchcolors == 0 ) or Npaths == 0 :
373
383
return
374
384
375
385
gc0 = self .new_gc ()
@@ -384,6 +394,7 @@ def cycle_or_default(seq, default=None):
384
394
toffsets = cycle_or_default (offset_trans .transform (offsets ), (0 , 0 ))
385
395
fcs = cycle_or_default (facecolors )
386
396
ecs = cycle_or_default (edgecolors )
397
+ hcs = cycle_or_default (hatchcolors )
387
398
lws = cycle_or_default (linewidths )
388
399
lss = cycle_or_default (linestyles )
389
400
aas = cycle_or_default (antialiaseds )
@@ -392,8 +403,8 @@ def cycle_or_default(seq, default=None):
392
403
if Nedgecolors == 0 :
393
404
gc0 .set_linewidth (0.0 )
394
405
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 ):
397
408
if not (np .isfinite (xo ) and np .isfinite (yo )):
398
409
continue
399
410
if Nedgecolors :
@@ -405,6 +416,8 @@ def cycle_or_default(seq, default=None):
405
416
gc0 .set_linewidth (0 )
406
417
else :
407
418
gc0 .set_foreground (ec )
419
+ if Nhatchcolors :
420
+ gc0 .set_hatch_color (hc )
408
421
if fc is not None and len (fc ) == 4 and fc [3 ] == 0 :
409
422
fc = None
410
423
gc0 .set_antialiased (aa )
0 commit comments