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