title: How to convert contour to marker for plotting?
body: <p>I have an <a href="https://www.pyimagesearch.com/2016/02/08/opencv-shape-detection/" rel="nofollow noreferrer">image</a>, for which I've extracted the contours using OpenCV and calculated their areas.</p>
  
  <pre class="lang-py prettyprint-override"><code>image = cv2.imread("shapes_and_colors.jpg")
  
  """Find contours"""
  gray = cv2.cvtColor(shapes.copy(), cv2.COLOR_BGR2GRAY)
  blur = cv2.GaussianBlur(gray, (5, 5), 0)
  thresh = cv2.threshold(src=blur, thresh=60, maxval=255, type=cv2.THRESH_BINARY)[1]
  new_image, contours, hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
  
  """Plot image and contours"""
  fig, ax = plt.subplots(ncols=2)
  ax[0].imshow(image)
  ax[0].axis('off')
  
  canvas = np.zeros_like(image)
  for i, c in enumerate(contours):
      M = cv2.moments(c)
      if M["m00"] != 0:
          cX = int((M["m10"] / M["m00"]))
          cY = int((M["m01"] / M["m00"]))
      else:
          cX,cY = 0,0
      cv2.drawContours(canvas, [c], -1, (255, 0, 255), 2)
      ax[1].text(x=cX, y=cY, s=u"{}".format(cv2.contourArea(c)), color="cyan", size=8)
  
  
  ax[1].imshow(canvas)
  ax[1].axis('off')
  
  plt.tight_layout()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Cmg5Z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Cmg5Z.png" alt="enter image description here"></a></p>
  
  <p>Now I'd like to plot them using the contour as the marker, something like:</p>
  
  <pre class="lang-py prettyprint-override"><code>fig, ax = plt.subplots()
  
  """Convert contour to marker"""
  def contour2marker(contour):
       ...
  
      return marker
  
  
  for i,c in enumerate(sorted(contours, key=cv2.contourArea)):
      ax.scatter(x=i, y=cv2.contourArea(c), marker=contour2marker(c))
  
  plt.tight_layout()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/rkDsz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rkDsz.png" alt="enter image description here"></a></p>
  
  <p>I don't know where to start with converting the contours to markers. I'm aware the contours are saved as a collection of points, and looking at <a href="https://stackoverflow.com/questions/28759253/how-to-crop-the-internal-area-of-a-contour">this post</a>, it is not straightforward to crop them out of an image. Rather, masks are created or rectangles are cropped out of images. However, if the shapes don't conform to regular polygons this technique doesn't work. If the contours could be converted to images then they could easily be plotted like in <a href="https://stackoverflow.com/questions/22566284/matplotlib-how-to-plot-images-instead-of-points">this example</a>.</p>