Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c23e5f6

Browse files
committed
another attempt; add a test
1 parent 3989c06 commit c23e5f6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/matplotlib/tests/test_tightlayout.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ def test_tight_layout7():
148148
ax.set_title('Right Title', loc='right', fontsize=fontsize)
149149
plt.tight_layout()
150150

151+
151152
@image_comparison(baseline_images=['tight_layout8'])
152153
def test_tight_layout8():
153154
'Test automatic use of tight_layout'
@@ -157,6 +158,15 @@ def test_tight_layout8():
157158
example_plot(ax, fontsize=24)
158159

159160

161+
@image_comparison(baseline_images=['tight_layout9'])
162+
def test_tight_layout9():
163+
# Test tight_layout for non-visible suplots
164+
# GH 8244
165+
f, axarr = plt.subplots(2, 2)
166+
axarr[1][1].set_visible(False)
167+
plt.tight_layout()
168+
169+
160170
# The following test is misleading when the text is removed.
161171
@image_comparison(baseline_images=['outward_ticks'], remove_text=False)
162172
def test_outward_ticks():

lib/matplotlib/tight_layout.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ def auto_adjust_subplotpars(fig, renderer,
123123
for subplots, ax_bbox, (num1, num2) in zip(subplot_list,
124124
ax_bbox_list,
125125
num1num2_list):
126-
tight_bbox_raw = union([ax.get_tightbbox(renderer) for ax in subplots if ax.get_visible()])
126+
if all([not ax.get_visible() for ax in subplots]):
127+
continue
128+
129+
tight_bbox_raw = union([ax.get_tightbbox(renderer) for ax in subplots])
127130
tight_bbox = TransformedBbox(tight_bbox_raw,
128131
fig.transFigure.inverted())
129132

0 commit comments

Comments
 (0)