title: Function to define an area in a colormap and return average pixel value
body: <p>I have a <code>.txt</code> of delimited data, about 600 x 600 cells in size. I have graphed it using matplotlib's <code>imshow</code> and now I want to analyze a specific part of interest in it. Particularly, I'm interested in drawing a defined region around a specific (x, y) point and returning the average value (from the file) within that region. I've done some searching but I can't find anything that will let me manipulate this as such. The closest thing I've come to is <code>patches</code> or the <code>patches.Circle</code> function, but all that does is let me draw a circle around the defined point. I can't extract (or can't figure out how to) any information from there. Here is my working example:</p>
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  import matplotlib.patches as patches
  
  #Setup Plots
  fig, ax = plt.subplots(figsize=(20, 10))
  plt.rcParams.update({'font.size': 20})
  #Open Data
  filename = &quot;smalltest.txt&quot;
  data = np.genfromtxt(filename, delimiter = &quot;;&quot;, skip_header = 0)
  
  #Colourmap
  ax.imshow(data, cmap ='hot', interpolation='nearest')
  
  #-------------------------------------
  #Average values around point
  
  #Create circle
  circ = patches.Circle((345, 195), 60, alpha=0.8, fc='none', 
  edgecolor = 'yellow')
  ax.add_patch(circ)
  
  fig.colorbar(ax.imshow(data, cmap ='hot', interpolation='nearest'), 
  label = &quot;Temperature (K)&quot;)
  plt.show()
  </code></pre>
  <p>Here is a picture as an example:
  <a href="https://i.stack.imgur.com/DoNM1.jpg" rel="nofollow noreferrer">Graph produced. Trying to get average value within the circle that is drawn</a></p>