Commit 4abd6e2
committed
BUG: Skip removed colorbar axes in constrained layout (fixes #31330)
When cbar.ax.remove() is called directly (bypassing Colorbar.remove()),
the parent axes' _colorbars list still holds a reference to the removed
colorbar Axes. On the next draw(), constrained layout crashes in
make_layout_margins() and reposition_axes() with:
AttributeError: 'NoneType' object has no attribute 'transSubfigure'
because get_pos_and_bbox() calls ax.get_figure(root=False) which
returns None for a removed Axes.
Fix: guard both _colorbars iteration loops against removed axes by
checking get_figure(root=False) is None and continuing.
Adds regression test.1 parent e9637a6 commit 4abd6e2
2 files changed
Lines changed: 27 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
401 | 405 | | |
402 | 406 | | |
403 | 407 | | |
| |||
688 | 692 | | |
689 | 693 | | |
690 | 694 | | |
| 695 | + | |
| 696 | + | |
691 | 697 | | |
692 | 698 | | |
693 | 699 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
809 | 809 | | |
810 | 810 | | |
811 | 811 | | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
0 commit comments