Simple plotting to show where boxes are
(fig, box, level=0, printit=True)
| 690 | |
| 691 | |
| 692 | def plot_children(fig, box, level=0, printit=True): |
| 693 | ''' |
| 694 | Simple plotting to show where boxes are |
| 695 | ''' |
| 696 | import matplotlib |
| 697 | import matplotlib.pyplot as plt |
| 698 | |
| 699 | if isinstance(fig, matplotlib.figure.Figure): |
| 700 | ax = fig.add_axes([0., 0., 1., 1.]) |
| 701 | ax.set_facecolor([1., 1., 1., 0.7]) |
| 702 | ax.set_alpha(0.3) |
| 703 | fig.draw(fig.canvas.get_renderer()) |
| 704 | else: |
| 705 | ax = fig |
| 706 | |
| 707 | import matplotlib.patches as patches |
| 708 | colors = plt.rcParams["axes.prop_cycle"].by_key()["color"] |
| 709 | if printit: |
| 710 | print("Level:", level) |
| 711 | for child in box.children: |
| 712 | rect = child.get_rect() |
| 713 | if printit: |
| 714 | print(child) |
| 715 | ax.add_patch( |
| 716 | patches.Rectangle( |
| 717 | (child.left.value(), child.bottom.value()), # (x,y) |
| 718 | child.width.value(), # width |
| 719 | child.height.value(), # height |
| 720 | fc='none', |
| 721 | alpha=0.8, |
| 722 | ec=colors[level] |
| 723 | ) |
| 724 | ) |
| 725 | if level > 0: |
| 726 | name = child.name.split('.')[-1] |
| 727 | if level % 2 == 0: |
| 728 | ax.text(child.left.value(), child.bottom.value(), name, |
| 729 | size=12-level, color=colors[level]) |
| 730 | else: |
| 731 | ax.text(child.right.value(), child.top.value(), name, |
| 732 | ha='right', va='top', size=12-level, |
| 733 | color=colors[level]) |
| 734 | |
| 735 | plot_children(ax, child, level=level+1, printit=printit) |
nothing calls this directly
no test coverage detected