diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 51716759645e..b830ddd3aa17 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -287,8 +287,11 @@ def __init__(self, *tight_layout* If *False* use *subplotpars*; if *True* adjust subplot - parameters using :meth:`tight_layout`. Defaults to - rc ``figure.autolayout``. + parameters using :meth:`tight_layout` with default padding. + When providing a dict containing the keys `pad`, `w_pad`, `h_pad` + and `rect`, the default :meth:`tight_layout` paddings will be + overridden. + Defaults to rc ``figure.autolayout``. """ Artist.__init__(self) @@ -393,12 +396,16 @@ def set_tight_layout(self, tight): Set whether :meth:`tight_layout` is used upon drawing. If None, the rcParams['figure.autolayout'] value will be set. - ACCEPTS: [True | False | None] + When providing a dict containing the keys `pad`, `w_pad`, `h_pad` + and `rect`, the default :meth:`tight_layout` paddings will be + overridden. + + ACCEPTS: [True | False | dict | None ] """ if tight is None: tight = rcParams['figure.autolayout'] - tight = bool(tight) - self._tight = tight + self._tight = bool(tight) + self._tight_parameters = tight if isinstance(tight, dict) else {} def autofmt_xdate(self, bottom=0.2, rotation=30, ha='right'): """ @@ -956,7 +963,7 @@ def draw(self, renderer): if self.get_tight_layout() and self.axes: try: - self.tight_layout(renderer) + self.tight_layout(renderer, **self._tight_parameters) except ValueError: pass # ValueError can occur when resizing a window. diff --git a/lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout8.pdf b/lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout8.pdf new file mode 100644 index 000000000000..c648289af926 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout8.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout8.png b/lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout8.png new file mode 100644 index 000000000000..9c15043c8200 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout8.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout8.svg b/lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout8.svg new file mode 100644 index 000000000000..281a4578d270 --- /dev/null +++ b/lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout8.svg @@ -0,0 +1,515 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/matplotlib/tests/test_tightlayout.py b/lib/matplotlib/tests/test_tightlayout.py index 1433305985f7..b6e1023df836 100644 --- a/lib/matplotlib/tests/test_tightlayout.py +++ b/lib/matplotlib/tests/test_tightlayout.py @@ -135,3 +135,11 @@ def test_tight_layout7(): ax.set_title('Left Title', loc='left', fontsize=fontsize) 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' + fig = plt.figure() + fig.set_tight_layout({'pad': .1}) + ax = fig.add_subplot(111) + example_plot(ax, fontsize=24)