fix columnnames and adjustaxis method signatures
[PyX.git] / manual / gradientname.py
blobb0493c59936c3f36dcac31c8df22b73c1c274a2f
1 #!/usr/bin/env python
3 # WARNING: THIS IS REALLY OLD CODE. IT COULD PROBABLY BE DONE USING GRAPHX NOWADAYS.
4 # HOWEVER, WE DON'T CARE. JUST DON'T TAKE THIS CODE TOO SERIOUSLY.
6 import sys, imp, re
7 sys.path[:0] = [".."]
8 import pyx
9 from pyx import *
11 text.set(mode="latex")
12 text.preamble(r"\renewcommand{\familydefault}{\ttdefault}")
14 c = canvas.canvas()
16 # data to be plotted
17 pf = graph.data.paramfunction("k", 0, 1, "color, xmin, xmax, ymin, ymax= k, k, 1, 0, 1")
19 # positioning is quite ugly ... but it works at the moment
20 y = 0
21 dy = -0.65
23 # we could use gradient.__dict__ to get the instances, but we
24 # would loose the ordering ... instead we just parse the file:
26 # see comment in colorname.py
28 p = re.compile("(?P<id>gradient\\.(?P<name>[a-z]+)) += [a-z]+gradient\\(.*\\)\n", re.IGNORECASE)
29 lines = imp.find_module("color", pyx.__path__)[0].readlines()
30 firstgraph = None
31 for line in lines: # we yet don't use a file iterator
32 m = p.match(line)
33 if m:
34 if firstgraph is None:
35 xaxis = graph.axis.lin(
36 parter=graph.axis.parter.lin(tickdists=["0.5","0.1"], labeldists=["1"]),
37 painter=graph.axis.painter.regular(
38 innerticklength=None,
39 outerticklength=graph.axis.painter.ticklength.normal),
40 linkpainter=graph.axis.painter.regular(innerticklength=None, labelattrs=None))
41 firstgraph = g = graph.graphxy(ypos=y, width=10, height=0.5, x2=xaxis, y=graph.axis.lin(parter=None))
42 else:
43 g = graph.graphxy(ypos=y, width=10, height=0.5, x2=graph.axis.linkedaxis(firstgraph.axes["x2"]), y=graph.axis.lin(parter=None))
44 g.plot(pf, [graph.style.rect(gradient=getattr(pyx.color.gradient, m.group("name")), keygraph=None)])
45 g.doplot()
46 g.finish()
47 c.insert(g)
48 c.text(10.2, y + 0.15, m.group("id"), [text.size.footnotesize])
49 y += dy
52 c.writePDFfile()