Skip to content Skip to sidebar Skip to footer

How To Check If Object Is Of Type "matplotlib.collections.polycollection"

For a specific task ( Link ) i want to check if an object is a : matplotlib.collections.PolyCollection or a: matplotlib.lines.Line2D object. I tired it like this: if isinstance(

Solution 1:

The solution to the initial problem is to actually import the module which provides the class for comparisson.

You simply lack import matplotlib.collections.

The next error is actually pretty self-explanatory. It says that it's impossible to compare two arrays.

So let's say the facecolor of h is [[ 0., 0.50196078, 0., 0.5]] and the facecolor of handle is [[ 1., 0.64705882, 0., 0.5]], then h.get_facecolor() == handle.get_facecolor() results in [[False False True True]]

Now, is two times false and two times true true or false? One cannot know. Therefore you need to use either any() or all() to decide if you want to know if any of the elements is True or if all of the elements are True.

Here you would want to check for the same color, thus use all:

np.all(h.get_facecolor() == handle.get_facecolor())

Post a Comment for "How To Check If Object Is Of Type "matplotlib.collections.polycollection""