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

Skip to content

Commit b23fd27

Browse files
committed
FIX: Address timhoffm review feedback
1 parent ca0515a commit b23fd27

2 files changed

Lines changed: 7 additions & 11 deletions

File tree

lib/matplotlib/contour.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ def clabel(self, levels=None, *,
144144
labels
145145
A list of `.Text` instances for the labels.
146146
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.
147+
Note: The returned Text instances should not be individually
148+
removed or have their geometry modified, e.g. by changing text or font size.
149+
If you need such a modification, remove the entire `.ContourSet` and recreate it.
150150
"""
151151

152152
if self.filled:
@@ -518,16 +518,14 @@ def labels(self, inline, inline_spacing):
518518

519519
def remove(self):
520520
super().remove()
521-
for text in list(self.labelTexts):
521+
for text in self.labelTexts:
522522
try:
523523
text.remove()
524524
except ValueError:
525-
import warnings
526-
warnings.warn(
525+
_api.warn_external(
527526
"Some labels were manually removed before the ContourSet. "
528527
"To remove labels cleanly, remove the entire ContourSet "
529-
"and recreate it.",
530-
UserWarning, stacklevel=2)
528+
"and recreate it.")
531529
self.labelTexts.clear()
532530

533531

lib/matplotlib/tests/test_contour.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -808,9 +808,7 @@ def test_contour_remove_with_labels():
808808
ax = plt.figure().add_subplot()
809809
cs = ax.contour(np.arange(16).reshape((4, 4)))
810810
labels = cs.clabel()
811-
for label in labels:
812-
label.remove()
813-
cs.clabel()
811+
labels[0].remove()
814812
with pytest.warns(UserWarning, match="Some labels were manually removed"):
815813
cs.remove()
816814

0 commit comments

Comments
 (0)