Skip to content

Commit bfde489

Browse files
committed
Ensure valid path mangling for ContourLabeler
1 parent 449cdb7 commit bfde489

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/matplotlib/contour.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,13 @@ def interp_vec(x, xp, fp): return [np.interp(x, xp, col) for col in fp.T]
418418
new_code_blocks = []
419419
if is_closed_path:
420420
if i0 != -1 and i1 != -1:
421-
new_xy_blocks.extend([[(x1, y1)], cc_xys[i1:i0+1], [(x0, y0)]])
422-
new_code_blocks.extend([[Path.MOVETO], [Path.LINETO] * (i0 + 2 - i1)])
421+
# This is probably wrong in the case that the entire contour would
422+
# be discarded, but ensures that a valid path is returned and is
423+
# consistent with behavior of mpl <3.8
424+
points = cc_xys[i1:i0+1]
425+
new_xy_blocks.extend([[(x1, y1)], points, [(x0, y0)]])
426+
nlines = len(points) + 1
427+
new_code_blocks.extend([[Path.MOVETO], [Path.LINETO] * nlines])
423428
else:
424429
if i0 != -1:
425430
new_xy_blocks.extend([cc_xys[:i0 + 1], [(x0, y0)]])

0 commit comments

Comments
 (0)