Skip to content

Instantly share code, notes, and snippets.

View amstrudy's full-sized avatar

Anja Sheppard amstrudy

View GitHub Profile
@amstrudy
amstrudy / area_between_curves.py
Created February 15, 2024 18:53
Find positive area between two curves in matplotlib
import math
import numpy as np
import matplotlib.pyplot as plt
from shapely.geometry import Polygon, LineString
from shapely.ops import unary_union, polygonize
# I found it very challenging to find code online that properly finds the positive area between two curves.
# Here is an example that works: we want the area between a sin function and y = 0, which for one full period of a sin function is 4.
# This script calculates this area to be 3.994... close enough!