fix typo
[PyX/mjg.git] / gallery / graphs / integral.py
blobf50c9bc64a7c854eb75936d61512d5ac87d7b0d0
1 from pyx import *
3 a, b = 2, 9 # integral area
5 p = graph.axis.painter.regular(basepathattrs=[deco.earrow.normal],
6 titlepos=0.98, titledirection=None)
7 ticks = [graph.axis.tick.tick(a, label="$a$"),
8 graph.axis.tick.tick(b, label="$b$")]
9 g = graph.graphxy(width=8, x2=None, y2=None,
10 x=graph.axis.linear(title="$x$", min=0, max=10,
11 manualticks=ticks,
12 parter=None, painter=p),
13 y=graph.axis.linear(title="$y$", parter=None, painter=p))
14 d = g.plot(graph.data.function("y(x)=(x-3)*(x-5)*(x-7)"))
15 g.finish()
16 p = d.path # the path is available after the graph is finished
18 pa = g.xgridpath(a)
19 pb = g.xgridpath(b)
20 (splita,), (splitpa,) = p.intersect(pa)
21 (splitb,), (splitpb,) = p.intersect(pb)
22 area = (pa.split([splitpa])[0] <<
23 p.split([splita, splitb])[1] <<
24 pb.split([splitpb])[0].reversed())
25 area[-1].close()
26 g.stroke(area, [deco.filled([color.gray(0.8)])])
27 g.text(g.pos(0.5 * (a + b), 0)[0], 1,
28 r"\int_a^b f(x){\rm d}x", [text.halign.center, text.mathmode])
29 g.writeEPSfile("integral")
30 g.writePDFfile("integral")