Skip to content

Commit edf5ebc

Browse files
rahulrathnavelmeeseeksmachine
authored andcommitted
Backport PR matplotlib#31706: Fix clabel manual index
1 parent c0e80b7 commit edf5ebc

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

lib/matplotlib/contour.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,8 @@ def add_label_near(self, x, y, inline=True, inline_spacing=5,
478478
label_width = self._get_nth_label_width(level)
479479
rotation, path = self._split_path_and_get_label_rotation(
480480
path, idx_vtx_min, proj, label_width, inline_spacing)
481-
self.add_label(*proj, rotation, self.labelLevelList[idx_level_min],
482-
self.labelCValueList[idx_level_min])
481+
self.add_label(*proj, rotation, self.labelLevelList[level],
482+
self.labelCValueList[level])
483483

484484
if inline:
485485
self._paths[idx_level_min] = path

lib/matplotlib/tests/test_contour.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,3 +891,10 @@ def test_contour_aliases(fig_test, fig_ref):
891891
def test_contour_singular_color():
892892
with pytest.raises(TypeError):
893893
plt.figure().add_subplot().contour([[0, 1], [2, 3]], color="r")
894+
895+
896+
def test_clabel_manual_subset():
897+
fig, ax = plt.subplots()
898+
cs = ax.contour([[1, 2], [3, 4]], levels=[1.5, 2.5, 3.5])
899+
# Attempt to label only one specific level manually
900+
ax.clabel(cs, levels=[2.5], manual=[(0.5, 0.5)])

0 commit comments

Comments
 (0)