From 48921714cc6d3bcf10112fa6bcccd6a7306b894b Mon Sep 17 00:00:00 2001 From: Michiel de Hoon Date: Sun, 2 Aug 2015 14:37:12 +0900 Subject: [PATCH 1/3] pyplot should call fig.set_tight_layout instead of fig.tight_layout to keep the frontend and the backend separate. This fixes issue 2654 --- lib/matplotlib/pyplot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 0eaa65eecb47..b8b60a69a9a4 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -1365,7 +1365,7 @@ def tight_layout(pad=1.08, h_pad=None, w_pad=None, rect=None): """ fig = gcf() - fig.tight_layout(pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect) + fig.set_tight_layout(dict(pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect)) def box(on=None): From 9ee8cca7510bbf7f71d8b48c91fcf3363482a320 Mon Sep 17 00:00:00 2001 From: Michiel de Hoon Date: Sun, 2 Aug 2015 14:57:14 +0900 Subject: [PATCH 2/3] also fix the examples in which figure.tight_layout instead of figure.set_tight_layout was called --- doc/users/plotting/colormaps/lightness.py | 2 +- examples/images_contours_and_fields/pcolormesh_levels.py | 2 +- examples/pylab_examples/markevery_demo.py | 8 ++++---- examples/pylab_examples/scatter_demo2.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/users/plotting/colormaps/lightness.py b/doc/users/plotting/colormaps/lightness.py index 2fe0721b688a..e54d020b9721 100644 --- a/doc/users/plotting/colormaps/lightness.py +++ b/doc/users/plotting/colormaps/lightness.py @@ -126,5 +126,5 @@ ax.set_xlabel(cmap_category + ' colormaps', fontsize=22) fig.text(-0.005, 0.55, 'Lightness $L^*$', fontsize=18, transform=fig.transFigure, rotation=90) - fig.tight_layout(h_pad=0.05) + fig.set_tight_layout(dict(h_pad=0.05)) plt.show() diff --git a/examples/images_contours_and_fields/pcolormesh_levels.py b/examples/images_contours_and_fields/pcolormesh_levels.py index 8e5015576399..e8a53f6ea418 100644 --- a/examples/images_contours_and_fields/pcolormesh_levels.py +++ b/examples/images_contours_and_fields/pcolormesh_levels.py @@ -48,6 +48,6 @@ # adjust spacing between subplots so `ax1` title and `ax0` tick labels # don't overlap -fig.tight_layout() +fig.set_tight_layout(True) plt.show() diff --git a/examples/pylab_examples/markevery_demo.py b/examples/pylab_examples/markevery_demo.py index 6b6495fac028..9b0a89a435f3 100644 --- a/examples/pylab_examples/markevery_demo.py +++ b/examples/pylab_examples/markevery_demo.py @@ -49,7 +49,7 @@ ax.append(fig1.add_subplot(gs[row, col])) ax[-1].set_title('markevery=%s' % str(case)) ax[-1].plot(x, y, 'o', ls='-', ms=4, markevery=case) -#fig1.tight_layout() +#fig1.set_tight_layout(True) # plot each markevery case for log x and y scales fig2 = plt.figure(num=2, figsize=figsize) @@ -62,7 +62,7 @@ axlog[-1].set_xscale('log') axlog[-1].set_yscale('log') axlog[-1].plot(x, y, 'o', ls='-', ms=4, markevery=case) -fig2.tight_layout() +fig2.set_tight_layout(True) # plot each markevery case for linear x and y scales but zoomed in # note the behaviour when zoomed in. When a start marker offset is specified @@ -78,7 +78,7 @@ axzoom[-1].plot(x, y, 'o', ls='-', ms=4, markevery=case) axzoom[-1].set_xlim((6, 6.7)) axzoom[-1].set_ylim((1.1, 1.7)) -fig3.tight_layout() +fig3.set_tight_layout(True) # define data for polar plots r = np.linspace(0, 3.0, 200) @@ -93,6 +93,6 @@ axpolar.append(fig4.add_subplot(gs[row, col], polar=True)) axpolar[-1].set_title('markevery=%s' % str(case)) axpolar[-1].plot(theta, r, 'o', ls='-', ms=4, markevery=case) -fig4.tight_layout() +fig4.set_tight_layout(True) plt.show() diff --git a/examples/pylab_examples/scatter_demo2.py b/examples/pylab_examples/scatter_demo2.py index 2814c360073d..3a34739d946b 100644 --- a/examples/pylab_examples/scatter_demo2.py +++ b/examples/pylab_examples/scatter_demo2.py @@ -27,6 +27,6 @@ ax.set_title('Volume and percent change') ax.grid(True) -fig.tight_layout() +fig.set_tight_layout(True) plt.show() From 102ed6dcf325345808659e4d0045aa83d47c85ac Mon Sep 17 00:00:00 2001 From: Michiel de Hoon Date: Thu, 6 Aug 2015 08:04:55 +0900 Subject: [PATCH 3/3] Revert "also fix the examples in which figure.tight_layout instead of figure.set_tight_layout was called" This reverts commit 9ee8cca7510bbf7f71d8b48c91fcf3363482a320. --- doc/users/plotting/colormaps/lightness.py | 2 +- examples/images_contours_and_fields/pcolormesh_levels.py | 2 +- examples/pylab_examples/markevery_demo.py | 8 ++++---- examples/pylab_examples/scatter_demo2.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/users/plotting/colormaps/lightness.py b/doc/users/plotting/colormaps/lightness.py index e54d020b9721..2fe0721b688a 100644 --- a/doc/users/plotting/colormaps/lightness.py +++ b/doc/users/plotting/colormaps/lightness.py @@ -126,5 +126,5 @@ ax.set_xlabel(cmap_category + ' colormaps', fontsize=22) fig.text(-0.005, 0.55, 'Lightness $L^*$', fontsize=18, transform=fig.transFigure, rotation=90) - fig.set_tight_layout(dict(h_pad=0.05)) + fig.tight_layout(h_pad=0.05) plt.show() diff --git a/examples/images_contours_and_fields/pcolormesh_levels.py b/examples/images_contours_and_fields/pcolormesh_levels.py index e8a53f6ea418..8e5015576399 100644 --- a/examples/images_contours_and_fields/pcolormesh_levels.py +++ b/examples/images_contours_and_fields/pcolormesh_levels.py @@ -48,6 +48,6 @@ # adjust spacing between subplots so `ax1` title and `ax0` tick labels # don't overlap -fig.set_tight_layout(True) +fig.tight_layout() plt.show() diff --git a/examples/pylab_examples/markevery_demo.py b/examples/pylab_examples/markevery_demo.py index 9b0a89a435f3..6b6495fac028 100644 --- a/examples/pylab_examples/markevery_demo.py +++ b/examples/pylab_examples/markevery_demo.py @@ -49,7 +49,7 @@ ax.append(fig1.add_subplot(gs[row, col])) ax[-1].set_title('markevery=%s' % str(case)) ax[-1].plot(x, y, 'o', ls='-', ms=4, markevery=case) -#fig1.set_tight_layout(True) +#fig1.tight_layout() # plot each markevery case for log x and y scales fig2 = plt.figure(num=2, figsize=figsize) @@ -62,7 +62,7 @@ axlog[-1].set_xscale('log') axlog[-1].set_yscale('log') axlog[-1].plot(x, y, 'o', ls='-', ms=4, markevery=case) -fig2.set_tight_layout(True) +fig2.tight_layout() # plot each markevery case for linear x and y scales but zoomed in # note the behaviour when zoomed in. When a start marker offset is specified @@ -78,7 +78,7 @@ axzoom[-1].plot(x, y, 'o', ls='-', ms=4, markevery=case) axzoom[-1].set_xlim((6, 6.7)) axzoom[-1].set_ylim((1.1, 1.7)) -fig3.set_tight_layout(True) +fig3.tight_layout() # define data for polar plots r = np.linspace(0, 3.0, 200) @@ -93,6 +93,6 @@ axpolar.append(fig4.add_subplot(gs[row, col], polar=True)) axpolar[-1].set_title('markevery=%s' % str(case)) axpolar[-1].plot(theta, r, 'o', ls='-', ms=4, markevery=case) -fig4.set_tight_layout(True) +fig4.tight_layout() plt.show() diff --git a/examples/pylab_examples/scatter_demo2.py b/examples/pylab_examples/scatter_demo2.py index 3a34739d946b..2814c360073d 100644 --- a/examples/pylab_examples/scatter_demo2.py +++ b/examples/pylab_examples/scatter_demo2.py @@ -27,6 +27,6 @@ ax.set_title('Volume and percent change') ax.grid(True) -fig.set_tight_layout(True) +fig.tight_layout() plt.show()