Skip to content

Instantly share code, notes, and snippets.

@AayushSameerShah
Created May 12, 2021 13:50
Show Gist options
  • Save AayushSameerShah/852546e913e782d04abbc09595e0f6f5 to your computer and use it in GitHub Desktop.
Save AayushSameerShah/852546e913e782d04abbc09595e0f6f5 to your computer and use it in GitHub Desktop.
This will give the shaded region in a graph... main part is under # Make shaded region comment
# SIMPLE chhe, Don't worry...
def func(x):
return x ** 2
x = np.linspace(0, 10)
y = func(x)
fig, ax = plt.subplots()
ax.plot(x, y, 'r', linewidth=2)
ax.set_ylim(bottom=0)
# Make the shaded region
a, b = 2, 9 # integral limits
ix = np.linspace(a, b)
iy = func(ix)
verts = [(a, 0), *zip(ix, iy), (b, 0)]
poly = Polygon(verts, facecolor='0.9', edgecolor='0.5')
ax.add_patch(poly)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment