title: How to check if object is of type "matplotlib.collections.PolyCollection"
body: <p>For a specific task ( <a href="https://stackoverflow.com/questions/44956501/global-legend-for-subplots-with-different-content">Link</a> ) i want to check if an object is a :</p>
  
  <pre><code>matplotlib.collections.PolyCollection
  </code></pre>
  
  <p>or a:</p>
  
  <pre><code>matplotlib.lines.Line2D
  </code></pre>
  
  <p>object.</p>
  
  <p>I tired it like this:</p>
  
  <pre><code> if isinstance(handle, matplotlib.collections.PolyCollection):
  </code></pre>
  
  <p>but this did not work. If would want to test if two variables h and handles are of the same type how would i check them both to bei either <em>matplotlib.collections.PolyCollection</em> or <em>matplotlib.lines.Line2D</em> objects? </p>
  
  <p><strong>Edit1</strong></p>
  
  <p>Here is the code in question wich adapts the solution in the above link:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import numpy as np
  import matplotlib.mlab as mlab
  import math
  
  
  def is_inlist(handle, handles):
      for h in handles:
          if h.get_color() == handle.get_color() and \
              h.get_linestyle() == handle.get_linestyle() and \
              h.get_marker() == handle.get_marker():
              return True
      return False
  
  
  lines=[]
  labels=[]
  legend_properties = {'weight':'bold','size':10}  
  # Example data
  
  
  mu = 0
  mu2 = 5
  variance = 1
  variance2 = 2
  sigma = math.sqrt(variance)
  sigma2 = math.sqrt(variance2)
  x = np.linspace(mu-3*variance,mu+3*variance, 100)
  x2 = np.linspace(mu2-3*variance2,mu2+3*variance2, 100)
  
  nrows = 4
  # Plot
  
  fig, axis = plt.subplots(nrows, sharex=True, sharey=False, figsize=(5, 8))
  fig.subplots_adjust(hspace=0.0001)
  #fig.suptitle("Stacked Plots with global Legend wich contains to little elements",fontsize=14,weight='bold')
  
  
  axis[0].fill_between(x+6,0,mlab.normpdf(x, mu, sigma), color='green',alpha=0.5,label="PEAK1", interpolate=True)
  axis[0].fill_between(x+4,0,mlab.normpdf(x, mu, sigma), color='orange',alpha=0.5,label="PEAK2", interpolate=True)
  axis[0].fill_between(x+3,0,mlab.normpdf(x, mu, sigma), color='blue',alpha=0.5,label="PEAK3", interpolate=True)
  axis[0].fill_between(x+7,0,mlab.normpdf(x, mu, sigma), color='red',alpha=0.5,label="PEAK4", interpolate=True)
  axis[0].plot(x2,2.5*mlab.normpdf(x2, mu2, sigma2),color='black',linestyle="",label="Exp", marker="o", markersize=4)
  
  axis[1].fill_between(x+6,0,mlab.normpdf(x, mu, sigma), color='green',alpha=0.5,label="PEAK1", interpolate=True)
  axis[1].fill_between(x+4,0,mlab.normpdf(x, mu, sigma), color='purple',alpha=0.5,label="PEAK2", interpolate=True)
  axis[1].fill_between(x+3,0,mlab.normpdf(x, mu, sigma), color='blue',alpha=0.5,label="PEAK3", interpolate=True)
  axis[1].fill_between(x+7,0,mlab.normpdf(x, mu, sigma), color='red',alpha=0.5,label="PEAK4", interpolate=True)
  axis[1].fill_between(x+6.5,0,mlab.normpdf(x, mu, sigma), color='yellow',alpha=0.5,label="PEAK5", interpolate=True)
  axis[1].plot(x2,2.5*mlab.normpdf(x2, mu2, sigma2),color='black',linestyle="",label="Exp", marker="o", markersize=4)
  
  axis[2].fill_between(x+6,0,mlab.normpdf(x, mu, sigma), color='green',alpha=0.5,label="PEAK1", interpolate=True)
  axis[2].fill_between(x+4,0,mlab.normpdf(x, mu, sigma), color='orange',alpha=0.5,label="PEAK2", interpolate=True)
  axis[2].fill_between(x+3,0,mlab.normpdf(x, mu, sigma), color='#73d216',alpha=0.5,label="PEAK3", interpolate=True)
  axis[2].fill_between(x+7,0,mlab.normpdf(x, mu, sigma), color='red',alpha=0.5,label="PEAK4", interpolate=True)
  axis[2].plot(x2,2.5*mlab.normpdf(x2, mu2, sigma2),color='black',linestyle="",label="Exp", marker="o", markersize=4)
  
  
  axis[3].fill_between(x+6,0,mlab.normpdf(x, mu, sigma), color='green',alpha=0.5,label="PEAK1", interpolate=True)
  axis[3].fill_between(x+4,0,mlab.normpdf(x, mu, sigma), color='purple',alpha=0.5,label="PEAK2", interpolate=True)
  axis[3].fill_between(x+3,0,mlab.normpdf(x, mu, sigma), color='blue',alpha=0.5,label="PEAK3", interpolate=True)
  axis[3].fill_between(x+7,0,mlab.normpdf(x, mu, sigma), color='red',alpha=0.5,label="PEAK4", interpolate=True)
  axis[3].fill_between(x+6.5,0,mlab.normpdf(x, mu, sigma), color='#73d216',alpha=0.5,label="PEAK5", interpolate=True)
  axis[3].fill_between(x+5.5,0,mlab.normpdf(x, mu, sigma), color='violet',alpha=0.5,label="PEAK6", interpolate=True)
  axis[3].plot(x2,2.5*mlab.normpdf(x2, mu2, sigma2),color='black',linestyle="",label="Exp", marker="o", markersize=4)
  
  
  
  
  
  
  
  for i in range(nrows):
      h, l = axis[i].get_legend_handles_labels()
      for hi, li in zip(h,l):
          if not is_inlist(hi, lines):
              lines.append(hi)
              labels.append(li)
  
  
  
  
  
  #x for x in item if x not in Z
  
  
  
  
  
  
  
  
  
  
  
  # only 3 Legend entrys Label1 , Label2 and Label3 are visible .. Differences in cloors and markers are ignored
  plt.legend(handles=lines, labels=labels,bbox_to_anchor=(0., nrows+.02, 1., .102), loc=3,ncol=3, prop=legend_properties,mode="expand", borderaxespad=0.,frameon=False,framealpha=0.0) 
  
  
  plt.show()
  </code></pre>
  
  <p>unfortunately it gives me the error :</p>
  
  <pre><code>    Traceback (most recent call last):
        File "PATH..../.py", line 76, in &lt;module&gt;
          if not is_inlist(hi, lines):
        File "PATH..../.py", line 9, in is_inlist
          if h.get_color() == handle.get_color() and \
      AttributeError: 'PolyCollection' object has no attribute 'get_color'
  </code></pre>
  
  <p>I was suggested to do a case analysis for each type of matplotlib object. this is where i struggle.
  I wanted to change the "is_inlist" function and to work for different cases. but the case analysis itself does not work yet:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import numpy as np
  import matplotlib.mlab as mlab
  import math
  
  
  def is_inlist(handle, handles):
      for h in handles:
          if isinstance(handle, matplotlib.collections.PolyCollection) and isinstance(h, matplotlib.collections.PolyCollection):
              if h.get_color() == handle.get_color() and \
                  h.get_linestyle() == handle.get_linestyle() and \
                  h.get_marker() == handle.get_marker():
                  return True
          if isinstance(handle, matplotlib.lines.Line2D) and isinstance(h, matplotlib.lines.Line2D):
              if h.get_color() == handle.get_color() and \
                  h.get_linestyle() == handle.get_linestyle() and \
                  h.get_marker() == handle.get_marker():
                  return True        
  
  
      return False
  
  
  lines=[]
  labels=[]
  legend_properties = {'weight':'bold','size':10}  
  # Example data
  
  
  mu = 0
  mu2 = 5
  variance = 1
  variance2 = 2
  sigma = math.sqrt(variance)
  sigma2 = math.sqrt(variance2)
  x = np.linspace(mu-3*variance,mu+3*variance, 100)
  x2 = np.linspace(mu2-3*variance2,mu2+3*variance2, 100)
  
  nrows = 4
  # Plot
  
  fig, axis = plt.subplots(nrows, sharex=True, sharey=False, figsize=(5, 8))
  fig.subplots_adjust(hspace=0.0001)
  #fig.suptitle("Stacked Plots with global Legend wich contains to little elements",fontsize=14,weight='bold')
  
  
  axis[0].fill_between(x+6,0,mlab.normpdf(x, mu, sigma), color='green',alpha=0.5,label="PEAK1", interpolate=True)
  axis[0].fill_between(x+4,0,mlab.normpdf(x, mu, sigma), color='orange',alpha=0.5,label="PEAK2", interpolate=True)
  axis[0].fill_between(x+3,0,mlab.normpdf(x, mu, sigma), color='blue',alpha=0.5,label="PEAK3", interpolate=True)
  axis[0].fill_between(x+7,0,mlab.normpdf(x, mu, sigma), color='red',alpha=0.5,label="PEAK4", interpolate=True)
  axis[0].plot(x2,2.5*mlab.normpdf(x2, mu2, sigma2),color='black',linestyle="",label="Exp", marker="o", markersize=4)
  
  axis[1].fill_between(x+6,0,mlab.normpdf(x, mu, sigma), color='green',alpha=0.5,label="PEAK1", interpolate=True)
  axis[1].fill_between(x+4,0,mlab.normpdf(x, mu, sigma), color='purple',alpha=0.5,label="PEAK2", interpolate=True)
  axis[1].fill_between(x+3,0,mlab.normpdf(x, mu, sigma), color='blue',alpha=0.5,label="PEAK3", interpolate=True)
  axis[1].fill_between(x+7,0,mlab.normpdf(x, mu, sigma), color='red',alpha=0.5,label="PEAK4", interpolate=True)
  axis[1].fill_between(x+6.5,0,mlab.normpdf(x, mu, sigma), color='yellow',alpha=0.5,label="PEAK5", interpolate=True)
  axis[1].plot(x2,2.5*mlab.normpdf(x2, mu2, sigma2),color='black',linestyle="",label="Exp", marker="o", markersize=4)
  
  axis[2].fill_between(x+6,0,mlab.normpdf(x, mu, sigma), color='green',alpha=0.5,label="PEAK1", interpolate=True)
  axis[2].fill_between(x+4,0,mlab.normpdf(x, mu, sigma), color='orange',alpha=0.5,label="PEAK2", interpolate=True)
  axis[2].fill_between(x+3,0,mlab.normpdf(x, mu, sigma), color='#73d216',alpha=0.5,label="PEAK3", interpolate=True)
  axis[2].fill_between(x+7,0,mlab.normpdf(x, mu, sigma), color='red',alpha=0.5,label="PEAK4", interpolate=True)
  axis[2].plot(x2,2.5*mlab.normpdf(x2, mu2, sigma2),color='black',linestyle="",label="Exp", marker="o", markersize=4)
  
  
  axis[3].fill_between(x+6,0,mlab.normpdf(x, mu, sigma), color='green',alpha=0.5,label="PEAK1", interpolate=True)
  axis[3].fill_between(x+4,0,mlab.normpdf(x, mu, sigma), color='purple',alpha=0.5,label="PEAK2", interpolate=True)
  axis[3].fill_between(x+3,0,mlab.normpdf(x, mu, sigma), color='blue',alpha=0.5,label="PEAK3", interpolate=True)
  axis[3].fill_between(x+7,0,mlab.normpdf(x, mu, sigma), color='red',alpha=0.5,label="PEAK4", interpolate=True)
  axis[3].fill_between(x+6.5,0,mlab.normpdf(x, mu, sigma), color='#73d216',alpha=0.5,label="PEAK5", interpolate=True)
  axis[3].fill_between(x+5.5,0,mlab.normpdf(x, mu, sigma), color='violet',alpha=0.5,label="PEAK6", interpolate=True)
  axis[3].plot(x2,2.5*mlab.normpdf(x2, mu2, sigma2),color='black',linestyle="",label="Exp", marker="o", markersize=4)
  
  
  
  for i in range(nrows):
      h, l = axis[i].get_legend_handles_labels()
      for hi, li in zip(h,l):
          if not is_inlist(hi, lines):
              lines.append(hi)
              labels.append(li)
  
  
  
  
  
  
  # only 3 Legend entrys Label1 , Label2 and Label3 are visible .. Differences in cloors and markers are ignored
  plt.legend(handles=lines, labels=labels,bbox_to_anchor=(0., nrows+.02, 1., .102), loc=3,ncol=3, prop=legend_properties,mode="expand", borderaxespad=0.,frameon=False,framealpha=0.0) 
  
  
  plt.show()
  </code></pre>
  
  <p>The error i get is:</p>
  
  <pre><code>    Traceback (most recent call last):
        File "Path/.. .py", line 84, in &lt;module&gt;
          if not is_inlist(hi, lines):
        File "Path/.. .py", line 9, in is_inlist
          if isinstance(handle, matplotlib.collections.PolyCollection) and isinstance(handle, matplotlib.collections.PolyCollection):
      NameError: global name 'matplotlib' is not defined
  </code></pre>
  
  <p><strong>Edit2</strong></p>
  
  <p>I added :</p>
  
  <pre><code>import matplotlib.collections
  </code></pre>
  
  <p>as i was suggested</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import numpy as np
  import matplotlib.mlab as mlab
  import math
  import matplotlib.collections
  
  def is_inlist(handle, handles):
      for h in handles:
          if isinstance(handle, matplotlib.collections.PolyCollection) and isinstance(h, matplotlib.collections.PolyCollection):
              if h.get_facecolor() == handle.get_facecolor() and \
                  h.get_linestyle() == handle.get_linestyle() and \
                  h.get_alpha() == handle.get_alpha():
                  return True
          if isinstance(handle, matplotlib.lines.Line2D) and isinstance(h, matplotlib.lines.Line2D):
              if h.get_color() == handle.get_color() and \
                  h.get_linestyle() == handle.get_linestyle() and \
                  h.get_marker() == handle.get_marker():
                  return True        
  
  
      return False
  
  
  lines=[]
  labels=[]
  legend_properties = {'weight':'bold','size':10}  
  # Example data
  
  
  mu = 0
  mu2 = 5
  variance = 1
  variance2 = 2
  sigma = math.sqrt(variance)
  sigma2 = math.sqrt(variance2)
  x = np.linspace(mu-3*variance,mu+3*variance, 100)
  x2 = np.linspace(mu2-3*variance2,mu2+3*variance2, 100)
  
  nrows = 4
  # Plot
  
  fig, axis = plt.subplots(nrows, sharex=True, sharey=False, figsize=(5, 8))
  fig.subplots_adjust(hspace=0.0001)
  #fig.suptitle("Stacked Plots with global Legend wich contains to little elements",fontsize=14,weight='bold')
  
  
  axis[0].fill_between(x+6,0,mlab.normpdf(x, mu, sigma), color='green',alpha=0.5,label="PEAK1", interpolate=True)
  axis[0].fill_between(x+4,0,mlab.normpdf(x, mu, sigma), color='orange',alpha=0.5,label="PEAK2", interpolate=True)
  axis[0].fill_between(x+3,0,mlab.normpdf(x, mu, sigma), color='blue',alpha=0.5,label="PEAK3", interpolate=True)
  axis[0].fill_between(x+7,0,mlab.normpdf(x, mu, sigma), color='red',alpha=0.5,label="PEAK4", interpolate=True)
  axis[0].plot(x2,2.5*mlab.normpdf(x2, mu2, sigma2),color='black',linestyle="",label="Exp", marker="o", markersize=4)
  
  axis[1].fill_between(x+6,0,mlab.normpdf(x, mu, sigma), color='green',alpha=0.5,label="PEAK1", interpolate=True)
  axis[1].fill_between(x+4,0,mlab.normpdf(x, mu, sigma), color='purple',alpha=0.5,label="PEAK2", interpolate=True)
  axis[1].fill_between(x+3,0,mlab.normpdf(x, mu, sigma), color='blue',alpha=0.5,label="PEAK3", interpolate=True)
  axis[1].fill_between(x+7,0,mlab.normpdf(x, mu, sigma), color='red',alpha=0.5,label="PEAK4", interpolate=True)
  axis[1].fill_between(x+6.5,0,mlab.normpdf(x, mu, sigma), color='yellow',alpha=0.5,label="PEAK5", interpolate=True)
  axis[1].plot(x2,2.5*mlab.normpdf(x2, mu2, sigma2),color='black',linestyle="",label="Exp", marker="o", markersize=4)
  
  axis[2].fill_between(x+6,0,mlab.normpdf(x, mu, sigma), color='green',alpha=0.5,label="PEAK1", interpolate=True)
  axis[2].fill_between(x+4,0,mlab.normpdf(x, mu, sigma), color='orange',alpha=0.5,label="PEAK2", interpolate=True)
  axis[2].fill_between(x+3,0,mlab.normpdf(x, mu, sigma), color='#73d216',alpha=0.5,label="PEAK3", interpolate=True)
  axis[2].fill_between(x+7,0,mlab.normpdf(x, mu, sigma), color='red',alpha=0.5,label="PEAK4", interpolate=True)
  axis[2].plot(x2,2.5*mlab.normpdf(x2, mu2, sigma2),color='black',linestyle="",label="Exp", marker="o", markersize=4)
  
  
  axis[3].fill_between(x+6,0,mlab.normpdf(x, mu, sigma), color='green',alpha=0.5,label="PEAK1", interpolate=True)
  axis[3].fill_between(x+4,0,mlab.normpdf(x, mu, sigma), color='purple',alpha=0.5,label="PEAK2", interpolate=True)
  axis[3].fill_between(x+3,0,mlab.normpdf(x, mu, sigma), color='blue',alpha=0.5,label="PEAK3", interpolate=True)
  axis[3].fill_between(x+7,0,mlab.normpdf(x, mu, sigma), color='red',alpha=0.5,label="PEAK4", interpolate=True)
  axis[3].fill_between(x+6.5,0,mlab.normpdf(x, mu, sigma), color='#73d216',alpha=0.5,label="PEAK5", interpolate=True)
  axis[3].fill_between(x+5.5,0,mlab.normpdf(x, mu, sigma), color='violet',alpha=0.5,label="PEAK6", interpolate=True)
  axis[3].plot(x2,2.5*mlab.normpdf(x2, mu2, sigma2),color='black',linestyle="",label="Exp", marker="o", markersize=4)
  
  
  
  for i in range(nrows):
      h, l = axis[i].get_legend_handles_labels()
      for hi, li in zip(h,l):
          if not is_inlist(hi, lines):
              lines.append(hi)
              labels.append(li)
  
  
  
  
  
  
  # only 3 Legend entrys Label1 , Label2 and Label3 are visible .. Differences in cloors and markers are ignored
  plt.legend(handles=lines, labels=labels,bbox_to_anchor=(0., nrows-1+.02, 1., .102), loc=3,ncol=3, prop=legend_properties,mode="expand", borderaxespad=0.,frameon=False,framealpha=0.0) 
  
  
  plt.show()
  </code></pre>
  
  <p>The error i get now is:</p>
  
  <pre><code>    Traceback (most recent call last):
        File "Path/.. .py", line 80, in &lt;module&gt;
          if not is_inlist(hi, lines):
        File "Dath/.. .py", line 10, in is_inlist
          if h.get_facecolor() == handle.get_facecolor() and \
      ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
  </code></pre>
  
  <p><strong>solution</strong>  based on the explanation of ImportanceOfBeingErnest:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import numpy as np
  import matplotlib.mlab as mlab
  import math
  import matplotlib.collections
  
  def is_inlist(handle, handles):
      for h in handles:
          if isinstance(handle, matplotlib.collections.PolyCollection) and isinstance(h, matplotlib.collections.PolyCollection): 
              if np.all(h.get_facecolor() == handle.get_facecolor()) and \
                  np.all(h.get_linestyle() == handle.get_linestyle()) and \
                  np.all(h.get_alpha() == handle.get_alpha()):
                  return True
          elif isinstance(handle, matplotlib.lines.Line2D) and isinstance(h, matplotlib.lines.Line2D):
              if h.get_color() == handle.get_color() and \
                  h.get_linestyle() == handle.get_linestyle() and \
                  h.get_marker() == handle.get_marker():
                  return True        
  
  
      return False
  
  
  lines=[]
  labels=[]
  legend_properties = {'weight':'bold','size':10}  
  # Example data
  
  
  mu = 0
  mu2 = 5
  variance = 1
  variance2 = 2
  sigma = math.sqrt(variance)
  sigma2 = math.sqrt(variance2)
  x = np.linspace(mu-3*variance,mu+3*variance, 100)
  x2 = np.linspace(mu2-3*variance2,mu2+3*variance2, 100)
  
  nrows = 4
  # Plot
  
  fig, axis = plt.subplots(nrows, sharex=True, sharey=False, figsize=(5, 8))
  fig.subplots_adjust(hspace=0.0001)
  #fig.suptitle("Stacked Plots with global Legend wich contains to little elements",fontsize=14,weight='bold')
  
  
  axis[0].fill_between(x+6,0,mlab.normpdf(x, mu, sigma), color='green',alpha=0.5,label="PEAK1", interpolate=True)
  axis[0].fill_between(x+4,0,mlab.normpdf(x, mu, sigma), color='orange',alpha=0.5,label="PEAK2", interpolate=True)
  axis[0].fill_between(x+3,0,mlab.normpdf(x, mu, sigma), color='blue',alpha=0.5,label="PEAK3", interpolate=True)
  axis[0].fill_between(x+7,0,mlab.normpdf(x, mu, sigma), color='red',alpha=0.5,label="PEAK4", interpolate=True)
  axis[0].plot(x2,2.5*mlab.normpdf(x2, mu2, sigma2),color='black',linestyle="",label="Exp", marker="o", markersize=4)
  
  axis[1].fill_between(x+6,0,mlab.normpdf(x, mu, sigma), color='green',alpha=0.5,label="PEAK1", interpolate=True)
  axis[1].fill_between(x+4,0,mlab.normpdf(x, mu, sigma), color='purple',alpha=0.5,label="PEAK2", interpolate=True)
  axis[1].fill_between(x+3,0,mlab.normpdf(x, mu, sigma), color='blue',alpha=0.5,label="PEAK3", interpolate=True)
  axis[1].fill_between(x+7,0,mlab.normpdf(x, mu, sigma), color='red',alpha=0.5,label="PEAK4", interpolate=True)
  axis[1].fill_between(x+6.5,0,mlab.normpdf(x, mu, sigma), color='yellow',alpha=0.5,label="PEAK5", interpolate=True)
  axis[1].plot(x2,2.5*mlab.normpdf(x2, mu2, sigma2),color='black',linestyle="",label="Exp", marker="o", markersize=4)
  
  axis[2].fill_between(x+6,0,mlab.normpdf(x, mu, sigma), color='green',alpha=0.5,label="PEAK1", interpolate=True)
  axis[2].fill_between(x+4,0,mlab.normpdf(x, mu, sigma), color='orange',alpha=0.5,label="PEAK2", interpolate=True)
  axis[2].fill_between(x+3,0,mlab.normpdf(x, mu, sigma), color='#73d216',alpha=0.5,label="PEAK3", interpolate=True)
  axis[2].fill_between(x+7,0,mlab.normpdf(x, mu, sigma), color='red',alpha=0.5,label="PEAK4", interpolate=True)
  axis[2].plot(x2,2.5*mlab.normpdf(x2, mu2, sigma2),color='black',linestyle="",label="Exp", marker="o", markersize=4)
  
  
  axis[3].fill_between(x+6,0,mlab.normpdf(x, mu, sigma), color='green',alpha=0.5,label="PEAK1", interpolate=True)
  axis[3].fill_between(x+4,0,mlab.normpdf(x, mu, sigma), color='purple',alpha=0.5,label="PEAK2", interpolate=True)
  axis[3].fill_between(x+3,0,mlab.normpdf(x, mu, sigma), color='blue',alpha=0.5,label="PEAK3", interpolate=True)
  axis[3].fill_between(x+7,0,mlab.normpdf(x, mu, sigma), color='red',alpha=0.5,label="PEAK4", interpolate=True)
  axis[3].fill_between(x+6.5,0,mlab.normpdf(x, mu, sigma), color='#73d216',alpha=0.5,label="PEAK5", interpolate=True)
  axis[3].fill_between(x+5.5,0,mlab.normpdf(x, mu, sigma), color='violet',alpha=0.5,label="PEAK6", interpolate=True)
  axis[3].plot(x2,2.5*mlab.normpdf(x2, mu2, sigma2),color='black',linestyle="",label="Exp", marker="o", markersize=4)
  
  
  
  for i in range(nrows):
      h, l = axis[i].get_legend_handles_labels()
      for hi, li in zip(h,l):
          if not is_inlist(hi, lines):
              lines.append(hi)
              labels.append(li)
  
  
  
  
  
  
  # only 3 Legend entrys Label1 , Label2 and Label3 are visible .. Differences in cloors and markers are ignored
  plt.legend(handles=lines, labels=labels,bbox_to_anchor=(0., nrows-1+.02, 1., .102), loc=3,ncol=3, prop=legend_properties,mode="expand", borderaxespad=0.,frameon=False,framealpha=0.0) 
  
  
  plt.show()
  </code></pre>