diff --git a/lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout9.pdf b/lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout9.pdf new file mode 100644 index 000000000000..c694c8431a21 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout9.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout9.png b/lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout9.png new file mode 100644 index 000000000000..2d63e6987a38 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout9.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout9.svg b/lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout9.svg new file mode 100644 index 000000000000..ea6a6ea62151 --- /dev/null +++ b/lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout9.svg @@ -0,0 +1,1017 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/matplotlib/tests/test_tightlayout.py b/lib/matplotlib/tests/test_tightlayout.py index d0a9cf5980ba..76d9c1424212 100644 --- a/lib/matplotlib/tests/test_tightlayout.py +++ b/lib/matplotlib/tests/test_tightlayout.py @@ -148,6 +148,7 @@ def test_tight_layout7(): ax.set_title('Right Title', loc='right', fontsize=fontsize) plt.tight_layout() + @image_comparison(baseline_images=['tight_layout8']) def test_tight_layout8(): 'Test automatic use of tight_layout' @@ -157,6 +158,15 @@ def test_tight_layout8(): example_plot(ax, fontsize=24) +@image_comparison(baseline_images=['tight_layout9']) +def test_tight_layout9(): + # Test tight_layout for non-visible suplots + # GH 8244 + f, axarr = plt.subplots(2, 2) + axarr[1][1].set_visible(False) + plt.tight_layout() + + # The following test is misleading when the text is removed. @image_comparison(baseline_images=['outward_ticks'], remove_text=False) def test_outward_ticks(): diff --git a/lib/matplotlib/tight_layout.py b/lib/matplotlib/tight_layout.py index 1f61d95e9f2f..9ca396dc0e3e 100644 --- a/lib/matplotlib/tight_layout.py +++ b/lib/matplotlib/tight_layout.py @@ -123,7 +123,11 @@ def auto_adjust_subplotpars(fig, renderer, for subplots, ax_bbox, (num1, num2) in zip(subplot_list, ax_bbox_list, num1num2_list): - tight_bbox_raw = union([ax.get_tightbbox(renderer) for ax in subplots]) + if all([not ax.get_visible() for ax in subplots]): + continue + + tight_bbox_raw = union([ax.get_tightbbox(renderer) for ax in subplots + if ax.get_visible()]) tight_bbox = TransformedBbox(tight_bbox_raw, fig.transFigure.inverted())