cleanups; all examples are working again
[PyX/mjg.git] / examples / graphs / integral.py
blob58feb78425577555428cbe8f3888c95a5d8ff934
1 from pyx import *
3 a, b = 2, 9 # integral area
5 p = graph.axispainter(basepathattrs=deco.earrow.normal(),
6 titlepos=0.98, titledirection=None)
7 g = graph.graphxy(width=8, x2=None, y2=None,
8 x=graph.linaxis(title="$x$", min=0, max=10,
9 part=[graph.tick(a, label="$a$"),
10 graph.tick(b, label="$b$")],
11 painter=p),
12 y=graph.linaxis(title="$y$",
13 part=None, painter=p))
14 style = g.plot(graph.function("y=(x-3)*(x-5)*(x-7)")).style
15 g.finish()
17 pa = g.xgridpath(a)
18 pb = g.xgridpath(b)
19 (splita,), (splitpa,) = style.path.intersect(pa)
20 (splitb,), (splitpb,) = style.path.intersect(pb)
21 area = (pa.split(splitpa)[0] <<
22 style.path.split(splita, splitb)[1] <<
23 pb.split(splitpb)[0].reversed())
24 area.append(path.closepath())
25 g.stroke(area, deco.filled(color.gray(0.8)))
26 g.text(g.pos(0.5 * (a + b), 0)[0], 1,
27 r"\int_a^b f(x){\rm d}x", text.halign.center, text.mathmode)
28 g.writetofile("integral")