title: How does matplotlib.path.contains_points interact with PolygonSelector?
body: <p>I'm fairly new to Python and am stuck on a problem...</p>
  
  <p>I'm trying to draw a region of interest (ROI) on an image and calculate the average pixel value in that ROI. </p>
  
  <p>To start, I tried the following - first I used <code>matplotlib.widgets.PolygonSelector</code> to draw a polygon, and then used <code>path.contains_points to create</code> a mask that I could then apply to the original image.</p>
  
  <pre><code>class ROIPolygon(object):
      def __init__(self, ax, row, col):
          self.canvas = ax.figure.canvas
          self.poly = PolygonSelector(ax,
                                      self.onselect,
                                      lineprops = dict(color = 'g', alpha = 1),
                                      markerprops = dict(mec = 'g', mfc = 'g', alpha = 1))
          self.path = None
  
      def onselect(self, verts):
          path = Path(verts)
          self.canvas.draw_idle()
          self.path = path
  
  def get_mask(drawn_roi, row, col):
      for i in np.arange(row):
          for j in np.arange(col):
               if drawn_roi.path.contains_points([(j,i)]) == [True]:
                   mask[i][j] = 1
      mask_bool = mask.astype(bool)
      mask_bool = ~mask_bool
      return mask_bool
  </code></pre>
  
  <p>But when I tested this out on a small image containing only 4 colored pixels, I get this image before drawing ROI:
  <a href="https://i.stack.imgur.com/JNY7N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JNY7N.png" alt="enter image description here"></a></p>
  
  <p>And this one after drawing ROI:
  <a href="https://i.stack.imgur.com/mQ7Cm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mQ7Cm.png" alt="enter image description here"></a> </p>
  
  <p>I expected the mask array to return only 4 False values.</p>
  
  <pre><code>[[ True  True  True  True  True  True  True  True  True  True]
   [ True  True  True  True  True  True  True  True  True  True]
   [ True  True  True  True  True  True  True  True  True  True]
   [ True  True  True  True  True  True  True  True  True  True]
   [ True  True  True  True  True False False  True  True  True]
   [ True  True  True  True  True False False  True  True  True]
   [ True  True  True  True  True  True  True  True  True  True]
   [ True  True  True  True  True  True  True  True  True  True]
   [ True  True  True  True  True  True  True  True  True  True]
   [ True  True  True  True  True  True  True  True  True  True]]
  </code></pre>
  
  <p>But instead it returned 12 False values. As well, if I were to draw the ROI even larger, I would return more False values.</p>
  
  <pre><code>[[ True  True  True  True  True  True  True  True  True  True]
   [ True  True  True  True  True  True  True  True  True  True]
   [ True  True  True  True  True  True  True  True  True  True]
   [ True  True  True  True  True  True  True  True  True  True]
   [ True  True  True  True False False False False  True  True]
   [ True  True  True  True False False False False  True  True]
   [ True  True  True  True False False False False  True  True]
   [ True  True  True  True  True  True  True  True  True  True]
   [ True  True  True  True  True  True  True  True  True  True]
   [ True  True  True  True  True  True  True  True  True  True]]
  
  </code></pre>
  
  <p>So I am wondering if there is something wrong with my approach, or if there is a particular interaction between the <code>PolygonSelector</code> and path.contains_points I am missing?</p>
  
  <p>Thanks!</p>