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

Skip to content

Commit e6818e7

Browse files
committed
Merge pull request #1065 from pwuertz/tight-layout-dpi-fix
fixed conversion from pt to inch in tight_layout
2 parents 267b0cf + 754535b commit e6818e7

5 files changed

Lines changed: 10 additions & 10 deletions

File tree

lib/matplotlib/figure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ def get_tightbbox(self, renderer):
13611361

13621362
return bbox_inches
13631363

1364-
def tight_layout(self, renderer=None, pad=1.2, h_pad=None, w_pad=None, rect=None):
1364+
def tight_layout(self, renderer=None, pad=1.08, h_pad=None, w_pad=None, rect=None):
13651365
"""
13661366
Adjust subplot parameters to give specified padding.
13671367

lib/matplotlib/gridspec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def locally_modified_subplot_params(self):
270270
return [k for k in self._AllowedKeys if getattr(self, k)]
271271

272272

273-
def tight_layout(self, fig, renderer=None, pad=1.2, h_pad=None, w_pad=None, rect=None):
273+
def tight_layout(self, fig, renderer=None, pad=1.08, h_pad=None, w_pad=None, rect=None):
274274
"""
275275
Adjust subplot parameters to give specified padding.
276276

lib/matplotlib/pyplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ def subplot_tool(targetfig=None):
11141114

11151115

11161116

1117-
def tight_layout(pad=1.2, h_pad=None, w_pad=None, rect=None):
1117+
def tight_layout(pad=1.08, h_pad=None, w_pad=None, rect=None):
11181118
"""
11191119
Adjust subplot parameters to give specified padding.
11201120

lib/matplotlib/tests/test_tightlayout.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def test_tight_layout6():
110110

111111
ax.set_xlabel("x-label", fontsize=12)
112112

113-
gs2.tight_layout(fig, rect=[0.5, 0, 1, 1], h_pad=0.5)
113+
gs2.tight_layout(fig, rect=[0.5, 0, 1, 1], h_pad=0.45)
114114

115115
top = min(gs1.top, gs2.top)
116116
bottom = max(gs1.bottom, gs2.bottom)
@@ -119,5 +119,5 @@ def test_tight_layout6():
119119
0.5, 1 - (gs1.top-top)])
120120
gs2.tight_layout(fig, rect=[0.5, 0 + (bottom-gs2.bottom),
121121
None, 1 - (gs2.top-top)],
122-
h_pad=0.5)
122+
h_pad=0.45)
123123

lib/matplotlib/tight_layout.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def auto_adjust_subplotpars(fig, renderer,
3838
num1num2_list,
3939
subplot_list,
4040
ax_bbox_list=None,
41-
pad=1.2, h_pad=None, w_pad=None,
41+
pad=1.08, h_pad=None, w_pad=None,
4242
rect=None):
4343
"""
4444
Return a dictionary of subplot parameters so that spacing between
@@ -71,15 +71,15 @@ def auto_adjust_subplotpars(fig, renderer,
7171

7272
rows, cols = nrows_ncols
7373

74-
pad_inches = pad * FontProperties(size=rcParams["font.size"]).get_size_in_points() / renderer.dpi
74+
pad_inches = pad * FontProperties(size=rcParams["font.size"]).get_size_in_points() / 72.
7575

7676
if h_pad is not None:
77-
vpad_inches = h_pad * FontProperties(size=rcParams["font.size"]).get_size_in_points() / renderer.dpi
77+
vpad_inches = h_pad * FontProperties(size=rcParams["font.size"]).get_size_in_points() / 72.
7878
else:
7979
vpad_inches = pad_inches
8080

8181
if w_pad is not None:
82-
hpad_inches = w_pad * FontProperties(size=rcParams["font.size"]).get_size_in_points() / renderer.dpi
82+
hpad_inches = w_pad * FontProperties(size=rcParams["font.size"]).get_size_in_points() / 72.
8383
else:
8484
hpad_inches = pad_inches
8585

@@ -210,7 +210,7 @@ def get_renderer(fig):
210210

211211

212212
def get_tight_layout_figure(fig, axes_list, renderer,
213-
pad=1.2, h_pad=None, w_pad=None, rect=None):
213+
pad=1.08, h_pad=None, w_pad=None, rect=None):
214214
"""
215215
return subplot parameters for tigh-layouted- figure with
216216
specified padding.

0 commit comments

Comments
 (0)