graph style/data rework basically finished (cleanups and improvements are still needed)
[PyX/mjg.git] / examples / graphs / integral.py
blobe38e644927db48b1ebcb839b29446b8bc0417eba
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-3)*(x-5)*(x-7)"))
15 g.finish()
16 p = d.styledata.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.append(path.closepath())
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")