Skip to content

Commit b2027c3

Browse files
committed
Add test of clabel with large padding
1 parent bfde489 commit b2027c3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/matplotlib/tests/test_contour.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,22 @@ def test_clabel_zorder(use_clabeltext, contour_zorder, clabel_zorder):
338338
assert clabel.get_zorder() == expected_clabel_zorder
339339

340340

341+
def test_clabel_with_large_spacing():
342+
# When the inline spacing is large relative to the contour, it may cause the
343+
# entire contour to be removed. In current implementation, one line segment is
344+
# retained between the identified points.
345+
# This behavior may be worth reconsidering, but check to be sure we do not produce
346+
# an invalid path, which results in an error at clabel call time.
347+
# see gh-27045 for more information
348+
x = y = np.arange(-3.0, 3.01, 0.05)
349+
X, Y = np.meshgrid(x, y)
350+
Z = np.exp(-X**2 - Y**2)
351+
352+
fig, ax = plt.subplots()
353+
contourset = ax.contour(X, Y, Z, levels=[0.01, 0.2, .5, .8])
354+
ax.clabel(contourset, inline_spacing=100)
355+
356+
341357
# tol because ticks happen to fall on pixel boundaries so small
342358
# floating point changes in tick location flip which pixel gets
343359
# the tick.

0 commit comments

Comments
 (0)