Skip to content

Commit 3928b66

Browse files
committed
Add 3x/scripts/integral_demo.py
1 parent c122abd commit 3928b66

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

docs/3x/scripts/integral_demo.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python
2+
3+
# implement the example graphs/integral from pyx
4+
from pylab import *
5+
from matplotlib.patches import Polygon
6+
7+
def func(x):
8+
return (x-3)*(x-5)*(x-7)+85
9+
10+
ax = subplot(111)
11+
12+
a, b = 2, 9 # integral area
13+
x = arange(0, 10, 0.01)
14+
y = func(x)
15+
plot(x, y, linewidth=1)
16+
17+
# make the shaded region
18+
ix = arange(a, b, 0.01)
19+
iy = func(ix)
20+
verts = [(a,0)] + list(zip(ix,iy)) + [(b,0)]
21+
poly = Polygon(verts, facecolor='0.8', edgecolor='k')
22+
ax.add_patch(poly)
23+
24+
text(0.5 * (a + b), 30,
25+
r"$\int_a^b f(x)\mathrm{d}x$", horizontalalignment='center',
26+
fontsize=20)
27+
28+
axis([0,10, 0, 180])
29+
figtext(0.9, 0.05, 'x')
30+
figtext(0.1, 0.9, 'y')
31+
ax.set_xticks((a,b))
32+
ax.set_xticklabels(('a','b'))
33+
ax.set_yticks([])
34+
show()

0 commit comments

Comments
 (0)