Skip to content

Commit 71060da

Browse files
committed
Clean up and move integral demo
1 parent 353ea06 commit 71060da

File tree

3 files changed

+43
-35
lines changed

3 files changed

+43
-35
lines changed

examples/pylab_examples/integral_demo.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

examples/showcase/integral_demo.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
Plot demonstrating the integral as the area under a curve.
3+
"""
4+
import numpy as np
5+
import matplotlib.pyplot as plt
6+
from matplotlib.patches import Polygon
7+
8+
def func(x):
9+
return (x-3)*(x-5)*(x-7)+85
10+
11+
fig, ax = plt.subplots()
12+
13+
a, b = 2, 9 # integral area
14+
x = np.linspace(0, 10)
15+
y = func(x)
16+
plt.plot(x, y, 'r', linewidth=2)
17+
18+
# make the shaded region
19+
ix = np.linspace(a, b)
20+
iy = func(ix)
21+
verts = [(a,0)] + list(zip(ix,iy)) + [(b,0)]
22+
poly = Polygon(verts, facecolor='0.9', edgecolor='0.5')
23+
ax.add_patch(poly)
24+
25+
plt.text(0.5 * (a + b), 30,
26+
r"$\int_a^b f(x)\mathrm{d}x$", horizontalalignment='center',
27+
fontsize=20)
28+
29+
plt.axis([0,10, 0, 180])
30+
plt.figtext(0.9, 0.05, '$x$')
31+
plt.figtext(0.1, 0.9, '$y$')
32+
33+
ax.spines['right'].set_visible(False)
34+
ax.spines['top'].set_visible(False)
35+
ax.set_xticks((a,b))
36+
ax.set_xticklabels(('$a$','$b$'))
37+
ax.set_yticks([])
38+
39+
plt.show()

examples/tests/backend_driver.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@
9191
'subplot_demo.py',
9292
]
9393

94+
files['showcase'] = [
95+
'integral_demo.py',
96+
]
97+
9498
files['pylab'] = [
9599
'accented_text.py',
96100
'alignment_test.py',
@@ -175,7 +179,6 @@
175179
'image_nonuniform.py',
176180
'image_origin.py',
177181
'image_slices_viewer.py',
178-
'integral_demo.py',
179182
'interp_demo.py',
180183
'invert_axes.py',
181184
'layer_images.py',

0 commit comments

Comments
 (0)