argument handling
[PyX/mjg.git] / manual / palettename.py
blob091d3ee4174585e3d9d00962b772d4d612270723
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.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:
21 p = re.compile("(?P<id>palette\\.(?P<name>[a-z]+)) += palette\\(.*\\)\n", re.IGNORECASE)
22 lines = imp.find_module("color", pyx.__path__)[0].readlines()
23 skiplevel = None
24 for line in lines: # we yet don't use a file iterator
25 m = p.match(line)
26 if m:
27 xaxis = graph.linaxis(datavmin=0, datavmax=1, part=graph.linpart(ticks=("0.5","0.1"), labels="1"),
28 painter=graph.axispainter(innerticklengths=None, labelattrs=None))
29 g = c.insert(graph.graphxy(ypos=y, width=10, height=0.5, x=xaxis,
30 x2=graph.linkaxis(xaxis,
31 skipticklevel=skiplevel,
32 skiplabellevel=skiplevel,
33 painter=graph.axispainter(innerticklengths=None,
34 outerticklengths=graph.axispainter.defaultticklengths)),
35 y=graph.linaxis(datavmin=0, datavmax=1, part=graph.manualpart(ticks=None))))
36 g.plot(pf, graph.rect(pyx.color.palette.__dict__[m.group("name")]))
37 g.dodata()
38 g.finish()
39 c.text(10.2, y + 0.15, m.group("id"), text.size.footnotesize)
40 y += dy
41 skiplevel = 0
44 c.writetofile("palettename", paperformat="a4")