|
32 | 32 | import importlib |
33 | 33 | import inspect |
34 | 34 | import io |
| 35 | +import itertools |
35 | 36 | import logging |
36 | 37 | import os |
37 | 38 | import re |
@@ -394,61 +395,57 @@ def _iter_collection(self, gc, master_transform, all_transforms, |
394 | 395 | *path_ids*; *gc* is a graphics context and *rgbFace* is a color to |
395 | 396 | use for filling the path. |
396 | 397 | """ |
397 | | - Ntransforms = len(all_transforms) |
398 | 398 | Npaths = len(path_ids) |
399 | 399 | Noffsets = len(offsets) |
400 | 400 | N = max(Npaths, Noffsets) |
401 | 401 | Nfacecolors = len(facecolors) |
402 | 402 | Nedgecolors = len(edgecolors) |
403 | 403 | Nlinewidths = len(linewidths) |
404 | 404 | Nlinestyles = len(linestyles) |
405 | | - Naa = len(antialiaseds) |
406 | 405 | Nurls = len(urls) |
407 | 406 |
|
408 | 407 | if (Nfacecolors == 0 and Nedgecolors == 0) or Npaths == 0: |
409 | 408 | return |
410 | | - if Noffsets: |
411 | | - toffsets = offsetTrans.transform(offsets) |
412 | 409 |
|
413 | 410 | gc0 = self.new_gc() |
414 | 411 | gc0.copy_properties(gc) |
415 | 412 |
|
416 | | - if Nfacecolors == 0: |
417 | | - rgbFace = None |
| 413 | + def cycle_or_default(seq, default=None): |
| 414 | + # Cycle over *seq* if it is not empty; else always yield *default*. |
| 415 | + return (itertools.cycle(seq) if len(seq) |
| 416 | + else itertools.repeat(default)) |
| 417 | + |
| 418 | + pathids = cycle_or_default(path_ids) |
| 419 | + toffsets = cycle_or_default(offsetTrans.transform(offsets), (0, 0)) |
| 420 | + fcs = cycle_or_default(facecolors) |
| 421 | + ecs = cycle_or_default(edgecolors) |
| 422 | + lws = cycle_or_default(linewidths) |
| 423 | + lss = cycle_or_default(linestyles) |
| 424 | + aas = cycle_or_default(antialiaseds) |
| 425 | + urls = cycle_or_default(urls) |
418 | 426 |
|
419 | 427 | if Nedgecolors == 0: |
420 | 428 | gc0.set_linewidth(0.0) |
421 | 429 |
|
422 | | - xo, yo = 0, 0 |
423 | | - for i in range(N): |
424 | | - path_id = path_ids[i % Npaths] |
425 | | - if Noffsets: |
426 | | - xo, yo = toffsets[i % Noffsets] |
| 430 | + for pathid, (xo, yo), fc, ec, lw, ls, aa, url in itertools.islice( |
| 431 | + zip(pathids, toffsets, fcs, ecs, lws, lss, aas, urls), N): |
427 | 432 | if not (np.isfinite(xo) and np.isfinite(yo)): |
428 | 433 | continue |
429 | | - if Nfacecolors: |
430 | | - rgbFace = facecolors[i % Nfacecolors] |
431 | 434 | if Nedgecolors: |
432 | 435 | if Nlinewidths: |
433 | | - gc0.set_linewidth(linewidths[i % Nlinewidths]) |
| 436 | + gc0.set_linewidth(lw) |
434 | 437 | if Nlinestyles: |
435 | | - gc0.set_dashes(*linestyles[i % Nlinestyles]) |
436 | | - fg = edgecolors[i % Nedgecolors] |
437 | | - if len(fg) == 4: |
438 | | - if fg[3] == 0.0: |
439 | | - gc0.set_linewidth(0) |
440 | | - else: |
441 | | - gc0.set_foreground(fg) |
| 438 | + gc0.set_dashes(*ls) |
| 439 | + if len(ec) == 4 and ec[3] == 0.0: |
| 440 | + gc0.set_linewidth(0) |
442 | 441 | else: |
443 | | - gc0.set_foreground(fg) |
444 | | - if rgbFace is not None and len(rgbFace) == 4: |
445 | | - if rgbFace[3] == 0: |
446 | | - rgbFace = None |
447 | | - gc0.set_antialiased(antialiaseds[i % Naa]) |
| 442 | + gc0.set_foreground(ec) |
| 443 | + if fc is not None and len(fc) == 4 and fc[3] == 0: |
| 444 | + fc = None |
| 445 | + gc0.set_antialiased(aa) |
448 | 446 | if Nurls: |
449 | | - gc0.set_url(urls[i % Nurls]) |
450 | | - |
451 | | - yield xo, yo, path_id, gc0, rgbFace |
| 447 | + gc0.set_url(url) |
| 448 | + yield xo, yo, pathid, gc0, fc |
452 | 449 | gc0.restore() |
453 | 450 |
|
454 | 451 | def get_image_magnification(self): |
|
0 commit comments