|
4 | 4 | import six |
5 | 5 | import warnings |
6 | 6 |
|
| 7 | + |
7 | 8 | import numpy as np |
| 9 | +import pytest |
8 | 10 |
|
9 | 11 | from matplotlib.testing.decorators import image_comparison |
10 | 12 | import matplotlib.pyplot as plt |
@@ -155,29 +157,19 @@ def test_constrained_layout8(): |
155 | 157 | fig.colorbar(pcm, ax=axs, pad=0.01, shrink=0.6) |
156 | 158 |
|
157 | 159 |
|
158 | | -@image_comparison(baseline_images=['constrained_layout7'], |
159 | | - extensions=['png']) |
160 | 160 | def test_constrained_layout7(): |
161 | 161 | 'Test for proper warning if fig not set in GridSpec' |
162 | | - fig = plt.figure(tight_layout=True) |
163 | | - gs = gridspec.GridSpec(1, 2) |
164 | | - gsl = gridspec.GridSpecFromSubplotSpec(2, 2, gs[0]) |
165 | | - gsr = gridspec.GridSpecFromSubplotSpec(1, 2, gs[1]) |
166 | | - axsl = [] |
167 | | - for gs in gsl: |
168 | | - ax = fig.add_subplot(gs) |
169 | | - axsl += [ax] |
170 | | - example_plot(ax, fontsize=12) |
171 | | - ax.set_xlabel('x-label\nMultiLine') |
172 | | - axsr = [] |
173 | | - for gs in gsr: |
174 | | - ax = fig.add_subplot(gs) |
175 | | - axsr += [ax] |
176 | | - pcm = example_pcolor(ax, fontsize=12) |
177 | | - |
178 | | - fig.colorbar(pcm, ax=axsr, pad=0.01, |
179 | | - shrink=0.99, location='bottom', |
180 | | - ticks=ticker.MaxNLocator(nbins=5)) |
| 162 | + with pytest.warns(UserWarning, match='Calling figure.constrained_layout, ' |
| 163 | + 'but figure not setup to do constrained layout'): |
| 164 | + fig = plt.figure(constrained_layout=True) |
| 165 | + gs = gridspec.GridSpec(1, 2) |
| 166 | + gsl = gridspec.GridSpecFromSubplotSpec(2, 2, gs[0]) |
| 167 | + gsr = gridspec.GridSpecFromSubplotSpec(1, 2, gs[1]) |
| 168 | + axsl = [] |
| 169 | + for gs in gsl: |
| 170 | + ax = fig.add_subplot(gs) |
| 171 | + # need to trigger a draw to get warning |
| 172 | + fig.draw(fig.canvas.get_renderer()) |
181 | 173 |
|
182 | 174 |
|
183 | 175 | @image_comparison(baseline_images=['constrained_layout8'], |
|
0 commit comments