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

Skip to content

Commit 17e5a80

Browse files
committed
Add QuadContourSet.remove.
1 parent 6c9c44d commit 17e5a80

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/matplotlib/contour.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,10 @@ def labels(self, inline, inline_spacing):
585585
if inline:
586586
paths[:] = additions
587587

588+
def remove(self):
589+
for text in self.labelTexts:
590+
text.remove()
591+
588592

589593
def _is_closed_polygon(X):
590594
"""
@@ -1389,6 +1393,11 @@ def find_nearest_contour(self, x, y, indices=None, pixel=True):
13891393

13901394
return (conmin, segmin, imin, xmin, ymin, d2min)
13911395

1396+
def remove(self):
1397+
super().remove()
1398+
for coll in self.collections:
1399+
coll.remove()
1400+
13921401

13931402
@_docstring.dedent_interpd
13941403
class QuadContourSet(ContourSet):

lib/matplotlib/tests/test_contour.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,3 +682,13 @@ def test_negative_linestyles(style):
682682
ax4.clabel(CS4, fontsize=9, inline=True)
683683
ax4.set_title(f'Single color - negative contours {style}')
684684
assert CS4.negative_linestyles == style
685+
686+
687+
def test_contour_remove():
688+
ax = plt.figure().add_subplot()
689+
orig_children = ax.get_children()
690+
cs = ax.contour(np.arange(16).reshape((4, 4)))
691+
cs.clabel()
692+
assert ax.get_children() != orig_children
693+
cs.remove()
694+
assert ax.get_children() == orig_children

0 commit comments

Comments
 (0)