fix call signature
[PyX/mjg.git] / manual / palettename.py
blob8b2185dc7ba323094d04a28b7803567f1f14a815
1 #!/usr/bin/env python
2 import sys, imp, re
3 sys.path[:0] = [".."]
4 import pyx
5 from pyx import *
7 text.set(mode="latex")
8 text.preamble(r"\renewcommand{\familydefault}{\ttdefault}")
10 c = canvas.canvas()
12 # data to be plotted
13 pf = graph.data.paramfunction("k", 0, 1, "color, xmin, xmax, ymin, ymax= k, k, 1, 0, 1")
15 # positioning is quite ugly ... but it works at the moment
16 y = 0
17 dy = -0.65
19 # we could use palette.__dict__ to get the instances, but we
20 # would loose the ordering ... instead we just parse the file:
22 # see comment in colorname.py
24 p = re.compile("(?P<id>palette\\.(?P<name>[a-z]+)) += palette\\(.*\\)\n", re.IGNORECASE)
25 lines = imp.find_module("color", pyx.__path__)[0].readlines()
26 first = 1
27 for line in lines: # we yet don't use a file iterator
28 m = p.match(line)
29 if m:
30 xaxis = graph.axis.lin(
31 parter=graph.axis.parter.lin(tickdist=("0.5","0.1"), labeldist="1"),
32 painter=graph.axis.painter.regular(innerticklength=None, labelattrs=None))
33 if first:
34 x2axis=graph.axis.linked(xaxis,
35 painter=graph.axis.painter.linked(
36 innerticklength=None,
37 outerticklength=graph.axis.painter.ticklength.normal,
38 labelattrs=[]))
39 first = 0
40 else:
41 x2axis=graph.axis.linked(xaxis, painter=graph.axis.painter.linked(innerticklength=None))
42 g = c.insert(graph.graphxy(ypos=y, width=10, height=0.5, x=xaxis, x2=x2axis, y=graph.axis.lin(parter=None)))
43 g.plot(pf, [graph.style.rect(getattr(pyx.color.palette, m.group("name")))])
44 g.dodata()
45 g.finish()
46 c.text(10.2, y + 0.15, m.group("id"), [text.size.footnotesize])
47 y += dy
50 c.writeEPSfile("palettename", paperformat="a4")