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

Skip to content

Commit bf2127b

Browse files
authored
Merge pull request #10387 from jklymak/tst-constrained-layout7-warning
TST: Small fix to constrainedlayout7 test (removed image)
2 parents b7d87d9 + ff90100 commit bf2127b

2 files changed

Lines changed: 13 additions & 21 deletions

File tree

Binary file not shown.

lib/matplotlib/tests/test_constrainedlayout.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import six
55
import warnings
66

7+
78
import numpy as np
9+
import pytest
810

911
from matplotlib.testing.decorators import image_comparison
1012
import matplotlib.pyplot as plt
@@ -155,29 +157,19 @@ def test_constrained_layout8():
155157
fig.colorbar(pcm, ax=axs, pad=0.01, shrink=0.6)
156158

157159

158-
@image_comparison(baseline_images=['constrained_layout7'],
159-
extensions=['png'])
160160
def test_constrained_layout7():
161161
'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())
181173

182174

183175
@image_comparison(baseline_images=['constrained_layout8'],

0 commit comments

Comments
 (0)