title: Find the area between two curves plotted in matplotlib (fill_between area)
body: <p>I have a list of <code>x</code> and <code>y</code> values for two curves, both having weird shapes, and I don't have a function for any of them. I need to do two things:</p>
  <ol>
  <li>Plot it and shade the area between the curves like the image below.</li>
  <li>Find the total area of this shaded region between the curves.</li>
  </ol>
  <p>I'm able to plot and shade the area between those curves with <code>fill_between</code> and <code>fill_betweenx</code> in <code>matplotlib</code>, but I have no idea on how to calculate the exact area between them, specially because I don't have a function for any of those curves.<br />
  Any ideas?</p>
  <p>I looked everywhere and can't find a simple solution for this. I'm quite desperate, so any help is much appreciated.</p>
  <p>Thank you very much!</p>
  <h2><img src="https://i.stack.imgur.com/avcBO.png" alt="Area between curves - how to calculate the area of the shaded region without curve's function?" /></h2>
  <hr />
  <p><strong>EDIT:</strong> For future reference (in case anyone runs into the same problem), here is how I've solved this: connected the first and last node/point of each curve together, resulting in a big weird-shaped polygon, then used <a href="https://pypi.python.org/pypi/Shapely" rel="nofollow noreferrer">shapely</a> to calculate the polygon's area automatically, which is the exact area between the curves, no matter which way they go or how nonlinear they are. Works like a charm! :)</p>
  <p>Here is my code:</p>
  <pre class="lang-py prettyprint-override"><code>from shapely.geometry import Polygon
  
  x_y_curve1 = [(0.121,0.232),(2.898,4.554),(7.865,9.987)] #these are your points for curve 1 (I just put some random numbers)
  x_y_curve2 = [(1.221,1.232),(3.898,5.554),(8.865,7.987)] #these are your points for curve 2 (I just put some random numbers)
  
  polygon_points = [] #creates a empty list where we will append the points to create the polygon
  
  for xyvalue in x_y_curve1:
      polygon_points.append([xyvalue[0],xyvalue[1]]) #append all xy points for curve 1
  
  for xyvalue in x_y_curve2[::-1]:
      polygon_points.append([xyvalue[0],xyvalue[1]]) #append all xy points for curve 2 in the reverse order (from last point to first point)
  
  for xyvalue in x_y_curve1[0:1]:
      polygon_points.append([xyvalue[0],xyvalue[1]]) #append the first point in curve 1 again, to it &quot;closes&quot; the polygon
  
  polygon = Polygon(polygon_points)
  area = polygon.area
  print(area)
  </code></pre>
  <p><strong>EDIT 2:</strong> Thank you for the answers. Like Kyle explained, this only works for positive values. If your curves go below 0 (which is not my case, as showed in the example chart), then you would have to work with absolute numbers.</p>