- adjustments to the new path + graph data and style handling
[PyX/mjg.git] / examples / graphs / partialfill.py
blobeb7fc3343000dd63f794193a858602d032f65b7b
1 # contributed by Michael Schindler
3 from pyx import *
5 # get the lines from the graph
6 xax = graph.axis.linear(min=-1, max=1.0, painter=None)
7 yax = graph.axis.linear(min=-1.3, max=1.3, painter=None)
8 g = graph.graphxy(width=10, ratio=2, x=xax, y=yax)
9 fline = g.plot(graph.data.function("y=sin(1.0/(x**2+0.02122))", points=1000))
10 horiz = g.plot(graph.data.function("y=0.5*x", points=2))
11 g.finish()
13 # convert paths to normpaths (for efficiency reasons only)
14 fline = fline.path.normpath()
15 horiz = horiz.path.normpath()
16 # intersect the lines
17 splith, splitf = horiz.intersect(fline)
19 # create gray area (we do not use simple clipping)
20 area = horiz.split([splith[0]])[0]
21 for i in range(0, len(splith)-2, 2):
22 area = area.joined(fline.split([splitf[i], splitf[i+1]])[1])
23 area = area.joined(horiz.split([splith[i+1], splith[i+2]])[1])
24 area = area.joined(fline.split([splitf[-2], splitf[-1]])[1])
25 area = area.joined(horiz.split([splith[-1]])[1])
26 area[-1].append(path.normline(*(area[-1].end_pt() + g.vpos_pt(1, 0))))
27 area[-1].append(path.normline(*(area[-1].end_pt() + g.vpos_pt(0, 0))))
28 area[-1].close()
30 c = canvas.canvas()
32 # draw first the area, then the function
33 c.fill(area, [color.gray(0.6)])
34 c.stroke(fline, [style.linewidth.Thick, style.linejoin.round])
36 c.writeEPSfile("partialfill")