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

Skip to content

Commit 6055d8a

Browse files
committed
Merge pull request #477 from efiring/findobj_no_duplicate
findobj: add kwarg to prevent duplicates in output. Closes issue #475.
2 parents fcc8039 + 32a2cdd commit 6055d8a

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

lib/matplotlib/artist.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -728,21 +728,25 @@ def set(self, **kwargs):
728728
ret.extend( [func(v)] )
729729
return ret
730730

731-
def findobj(self, match=None):
731+
def findobj(self, match=None, include_self=True):
732732
"""
733733
pyplot signature:
734-
findobj(o=gcf(), match=None)
734+
findobj(o=gcf(), match=None, include_self=True)
735735
736736
Recursively find all :class:matplotlib.artist.Artist instances
737737
contained in self.
738738
739739
*match* can be
740740
741-
- None: return all objects contained in artist (including artist)
741+
- None: return all objects contained in artist.
742+
743+
- function with signature ``boolean = match(artist)``
744+
used to filter matches
742745
743-
- function with signature ``boolean = match(artist)`` used to filter matches
746+
- class instance: eg Line2D. Only return artists of class type.
744747
745-
- class instance: eg Line2D. Only return artists of class type
748+
If *include_self* is True (default), include self in the list to be
749+
checked for a match.
746750
747751
.. plot:: mpl_examples/pylab_examples/findobj_demo.py
748752
"""
@@ -755,17 +759,18 @@ def matchfunc(x):
755759
elif callable(match):
756760
matchfunc = match
757761
else:
758-
raise ValueError('match must be None, an matplotlib.artist.Artist subclass, or a callable')
759-
762+
raise ValueError('match must be None, a matplotlib.artist.Artist subclass, or a callable')
760763

761764
artists = []
762765

763766
for c in self.get_children():
764767
if matchfunc(c):
765768
artists.append(c)
766-
artists.extend([thisc for thisc in c.findobj(matchfunc) if matchfunc(thisc)])
769+
artists.extend([thisc for thisc in
770+
c.findobj(matchfunc, include_self=False)
771+
if matchfunc(thisc)])
767772

768-
if matchfunc(self):
773+
if include_self and matchfunc(self):
769774
artists.append(self)
770775
return artists
771776

0 commit comments

Comments
 (0)