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

Skip to content

Commit d35b9cd

Browse files
committed
FIX: Add warning and docs for manual label removal in ContourSet
1 parent 8038b61 commit d35b9cd

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

lib/matplotlib/contour.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ def clabel(self, levels=None, *,
143143
-------
144144
labels
145145
A list of `.Text` instances for the labels.
146+
147+
Note: The returned .Text instances should not be individually
148+
removed or have their geometry modified. To remove all labels,
149+
remove the entire .ContourSet and recreate it.
146150
"""
147151

148152
if self.filled:
@@ -518,7 +522,12 @@ def remove(self):
518522
try:
519523
text.remove()
520524
except ValueError:
521-
pass
525+
import warnings
526+
warnings.warn(
527+
"Some labels were manually removed before the ContourSet. "
528+
"To remove labels cleanly, remove the entire ContourSet "
529+
"and recreate it.",
530+
UserWarning, stacklevel=2)
522531
self.labelTexts.clear()
523532

524533

0 commit comments

Comments
 (0)