|
2 | 2 | unicode_literals)
|
3 | 3 |
|
4 | 4 | import six
|
| 5 | +import warnings |
5 | 6 |
|
6 | 7 | import numpy as np
|
7 | 8 |
|
|
10 | 11 | from nose.tools import assert_raises
|
11 | 12 | from numpy.testing import assert_array_equal
|
12 | 13 |
|
| 14 | + |
13 | 15 | 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 | + |
19 | 22 |
|
20 | 23 | @image_comparison(baseline_images=['tight_layout1'])
|
21 | 24 | def test_tight_layout1():
|
@@ -81,50 +84,54 @@ def test_tight_layout5():
|
81 | 84 | fig = plt.figure()
|
82 | 85 |
|
83 | 86 | ax = plt.subplot(111)
|
84 |
| - arr = np.arange(100).reshape((10,10)) |
| 87 | + arr = np.arange(100).reshape((10, 10)) |
85 | 88 | ax.imshow(arr, interpolation="none")
|
86 | 89 |
|
87 | 90 | plt.tight_layout()
|
88 | 91 |
|
89 | 92 |
|
90 |
| - |
91 | 93 | @image_comparison(baseline_images=['tight_layout6'])
|
92 | 94 | def test_tight_layout6():
|
93 | 95 | 'Test tight_layout for gridspec'
|
94 | 96 |
|
95 |
| - fig = plt.figure() |
| 97 | + # This raises warnings since tight layout cannot |
| 98 | + # do this fully automatically. But the test is |
| 99 | + # correct since the layout is manually edited |
| 100 | + with warnings.catch_warnings(): |
| 101 | + warnings.simplefilter("ignore", UserWarning) |
| 102 | + fig = plt.figure() |
96 | 103 |
|
97 |
| - import matplotlib.gridspec as gridspec |
| 104 | + import matplotlib.gridspec as gridspec |
98 | 105 |
|
99 |
| - gs1 = gridspec.GridSpec(2, 1) |
100 |
| - ax1 = fig.add_subplot(gs1[0]) |
101 |
| - ax2 = fig.add_subplot(gs1[1]) |
| 106 | + gs1 = gridspec.GridSpec(2, 1) |
| 107 | + ax1 = fig.add_subplot(gs1[0]) |
| 108 | + ax2 = fig.add_subplot(gs1[1]) |
102 | 109 |
|
103 |
| - example_plot(ax1) |
104 |
| - example_plot(ax2) |
| 110 | + example_plot(ax1) |
| 111 | + example_plot(ax2) |
105 | 112 |
|
106 |
| - gs1.tight_layout(fig, rect=[0, 0, 0.5, 1]) |
| 113 | + gs1.tight_layout(fig, rect=[0, 0, 0.5, 1]) |
107 | 114 |
|
108 |
| - gs2 = gridspec.GridSpec(3, 1) |
| 115 | + gs2 = gridspec.GridSpec(3, 1) |
109 | 116 |
|
110 |
| - for ss in gs2: |
111 |
| - ax = fig.add_subplot(ss) |
112 |
| - example_plot(ax) |
113 |
| - ax.set_title("") |
114 |
| - ax.set_xlabel("") |
| 117 | + for ss in gs2: |
| 118 | + ax = fig.add_subplot(ss) |
| 119 | + example_plot(ax) |
| 120 | + ax.set_title("") |
| 121 | + ax.set_xlabel("") |
115 | 122 |
|
116 |
| - ax.set_xlabel("x-label", fontsize=12) |
| 123 | + ax.set_xlabel("x-label", fontsize=12) |
117 | 124 |
|
118 |
| - gs2.tight_layout(fig, rect=[0.5, 0, 1, 1], h_pad=0.45) |
| 125 | + gs2.tight_layout(fig, rect=[0.5, 0, 1, 1], h_pad=0.45) |
119 | 126 |
|
120 |
| - top = min(gs1.top, gs2.top) |
121 |
| - bottom = max(gs1.bottom, gs2.bottom) |
| 127 | + top = min(gs1.top, gs2.top) |
| 128 | + bottom = max(gs1.bottom, gs2.bottom) |
122 | 129 |
|
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) |
| 130 | + gs1.tight_layout(fig, rect=[None, 0 + (bottom-gs1.bottom), |
| 131 | + 0.5, 1 - (gs1.top-top)]) |
| 132 | + gs2.tight_layout(fig, rect=[0.5, 0 + (bottom-gs2.bottom), |
| 133 | + None, 1 - (gs2.top-top)], |
| 134 | + h_pad=0.45) |
128 | 135 |
|
129 | 136 |
|
130 | 137 | @image_comparison(baseline_images=['tight_layout7'])
|
|
0 commit comments