Test tight_layout for gridspec.
()
| 80 | |
| 81 | @image_comparison(['tight_layout6'], style='mpl20') |
| 82 | def test_tight_layout6(): |
| 83 | """Test tight_layout for gridspec.""" |
| 84 | |
| 85 | # This raises warnings since tight layout cannot |
| 86 | # do this fully automatically. But the test is |
| 87 | # correct since the layout is manually edited |
| 88 | with warnings.catch_warnings(): |
| 89 | warnings.simplefilter("ignore", UserWarning) |
| 90 | fig = plt.figure() |
| 91 | |
| 92 | gs1 = mpl.gridspec.GridSpec(2, 1) |
| 93 | ax1 = fig.add_subplot(gs1[0]) |
| 94 | ax2 = fig.add_subplot(gs1[1]) |
| 95 | |
| 96 | example_plot(ax1) |
| 97 | example_plot(ax2) |
| 98 | |
| 99 | gs1.tight_layout(fig, rect=[0, 0, 0.5, 1]) |
| 100 | |
| 101 | gs2 = mpl.gridspec.GridSpec(3, 1) |
| 102 | |
| 103 | for ss in gs2: |
| 104 | ax = fig.add_subplot(ss) |
| 105 | example_plot(ax) |
| 106 | ax.set_title("") |
| 107 | ax.set_xlabel("") |
| 108 | |
| 109 | ax.set_xlabel("x-label", fontsize=12) |
| 110 | |
| 111 | gs2.tight_layout(fig, rect=[0.5, 0, 1, 1], h_pad=0.45) |
| 112 | |
| 113 | top = min(gs1.top, gs2.top) |
| 114 | bottom = max(gs1.bottom, gs2.bottom) |
| 115 | |
| 116 | gs1.tight_layout(fig, rect=[None, 0 + (bottom-gs1.bottom), |
| 117 | 0.5, 1 - (gs1.top-top)]) |
| 118 | gs2.tight_layout(fig, rect=[0.5, 0 + (bottom-gs2.bottom), |
| 119 | None, 1 - (gs2.top-top)], |
| 120 | h_pad=0.45) |
| 121 | |
| 122 | |
| 123 | @image_comparison(['tight_layout7'], style='mpl20') |
nothing calls this directly
no test coverage detected
searching dependent graphs…