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

Skip to content

Commit 155e1f7

Browse files
committed
Catch warnings in tightlayout test.
These are warnings that are raised because tightlayout does not work fully automatic on gridspec. However, the point of the test is doing this with some manual help so this works as expected.
1 parent c56ece1 commit 155e1f7

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed

lib/matplotlib/tests/test_tightlayout.py

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
unicode_literals)
33

44
import six
5+
import warnings
56

67
import numpy as np
78

@@ -10,12 +11,14 @@
1011
from nose.tools import assert_raises
1112
from numpy.testing import assert_array_equal
1213

14+
1315
def example_plot(ax, fontsize=12):
14-
ax.plot([1, 2])
15-
ax.locator_params(nbins=3)
16-
ax.set_xlabel('x-label', fontsize=fontsize)
17-
ax.set_ylabel('y-label', fontsize=fontsize)
18-
ax.set_title('Title', fontsize=fontsize)
16+
ax.plot([1, 2])
17+
ax.locator_params(nbins=3)
18+
ax.set_xlabel('x-label', fontsize=fontsize)
19+
ax.set_ylabel('y-label', fontsize=fontsize)
20+
ax.set_title('Title', fontsize=fontsize)
21+
1922

2023
@image_comparison(baseline_images=['tight_layout1'])
2124
def test_tight_layout1():
@@ -81,50 +84,51 @@ def test_tight_layout5():
8184
fig = plt.figure()
8285

8386
ax = plt.subplot(111)
84-
arr = np.arange(100).reshape((10,10))
87+
arr = np.arange(100).reshape((10, 10))
8588
ax.imshow(arr, interpolation="none")
8689

8790
plt.tight_layout()
8891

8992

90-
9193
@image_comparison(baseline_images=['tight_layout6'])
9294
def test_tight_layout6():
9395
'Test tight_layout for gridspec'
9496

95-
fig = plt.figure()
97+
with warnings.catch_warnings():
98+
warnings.simplefilter("ignore", UserWarning)
99+
fig = plt.figure()
96100

97-
import matplotlib.gridspec as gridspec
101+
import matplotlib.gridspec as gridspec
98102

99-
gs1 = gridspec.GridSpec(2, 1)
100-
ax1 = fig.add_subplot(gs1[0])
101-
ax2 = fig.add_subplot(gs1[1])
103+
gs1 = gridspec.GridSpec(2, 1)
104+
ax1 = fig.add_subplot(gs1[0])
105+
ax2 = fig.add_subplot(gs1[1])
102106

103-
example_plot(ax1)
104-
example_plot(ax2)
107+
example_plot(ax1)
108+
example_plot(ax2)
105109

106-
gs1.tight_layout(fig, rect=[0, 0, 0.5, 1])
110+
gs1.tight_layout(fig, rect=[0, 0, 0.5, 1])
107111

108-
gs2 = gridspec.GridSpec(3, 1)
112+
gs2 = gridspec.GridSpec(3, 1)
109113

110-
for ss in gs2:
111-
ax = fig.add_subplot(ss)
112-
example_plot(ax)
113-
ax.set_title("")
114-
ax.set_xlabel("")
114+
for ss in gs2:
115+
ax = fig.add_subplot(ss)
116+
example_plot(ax)
117+
ax.set_title("")
118+
ax.set_xlabel("")
115119

116-
ax.set_xlabel("x-label", fontsize=12)
120+
ax.set_xlabel("x-label", fontsize=12)
117121

118-
gs2.tight_layout(fig, rect=[0.5, 0, 1, 1], h_pad=0.45)
122+
gs2.tight_layout(fig, rect=[0.5, 0, 1, 1], h_pad=0.45)
119123

120-
top = min(gs1.top, gs2.top)
121-
bottom = max(gs1.bottom, gs2.bottom)
124+
top = min(gs1.top, gs2.top)
125+
bottom = max(gs1.bottom, gs2.bottom)
122126

123-
gs1.tight_layout(fig, rect=[None, 0 + (bottom-gs1.bottom),
124-
0.5, 1 - (gs1.top-top)])
125-
gs2.tight_layout(fig, rect=[0.5, 0 + (bottom-gs2.bottom),
126-
None, 1 - (gs2.top-top)],
127-
h_pad=0.45)
127+
gs1.tight_layout(fig, rect=[None, 0 + (bottom-gs1.bottom),
128+
0.5, 1 - (gs1.top-top)])
129+
gs2.tight_layout(fig, rect=[0.5, 0 + (bottom-gs2.bottom),
130+
None, 1 - (gs2.top-top)],
131+
h_pad=0.45)
128132

129133

130134
@image_comparison(baseline_images=['tight_layout7'])

0 commit comments

Comments
 (0)