Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 475
1
from pylab import *
2
from matplotlib.patches import Polygon
3
4
def func(x):
5
return (x-3)*(x-5)*(x-7)+85
6
7
def integral_plot(f):
8
ax = subplot(111)
9
a, b = 2, 9 # integral area
10
x = arange(0, 10, 0.01)
11
y = f(x)
12
plot(x, y, linewidth=1)
13
# make the shaded region
14
ix = arange(a, b, 0.01)
15
iy = func(ix)
16
verts = [(a,0)] + list(zip(ix,iy)) + [(b,0)]
17
poly = Polygon(verts, facecolor='0.8', edgecolor='k')
18
ax.add_patch(poly)
19
20
text(0.5 * (a + b), 30,
21
r"$\int_a^b f(x)\mathrm{d}x$", horizontalalignment='center',
22
fontsize=20)
23
24
axis([0,10, 0, 180])
25
figtext(0.9, 0.05, 'x')
26
figtext(0.1, 0.9, 'y')
27
ax.set_xticks((a,b))
28
ax.set_xticklabels((r'$a$',r'$b$'))
29
ax.set_yticks([])
30
show ()
31