Hi,
sorry for my late response (to this and the other mails I'll answer
today). I was in Vienna last week ... ;)
On 05.04.05, Michael Strass wrote:
> So here is my problem: I want to plot 4 data sets in one graph also
> displaying a legend. So I use the class key for this purpose. It seems
> to me from reading the _reference_ manual that you can only arrange the
> key entries vertically that means in one column. Due the space left
> inside my graph it would be better to have two rows with two columns.
> How does it work, if at all?
The current graph key class does not allow you to do so. However you
can use your own graph key class. And its even not that complicated
since you can use the existing key each of the columns. Thats why we
do all this component architecture in the graph system! A modifed
version of the piaxis example would be:
from math import pi
from pyx import *
from pyx.graph import axis
class columnkey:
def __init__(self, columns=2, dist=0.5*unit.v_cm, subkey=graph.key.key(),
border=0.3*unit.v_cm, keyattrs=None):
self.columns = columns
self.dist = dist
self.subkey = subkey
self.border = border
self.keyattrs = keyattrs
# copy some config features from the subkey
# TODO: the positioning config should be moved into the graph
self.hinside = subkey.hinside
self.vinside = subkey.vinside
self.hdist = subkey.hdist
self.vdist = subkey.vdist
self.hpos = subkey.hpos
self.vpos = subkey.vpos
def paint(self, plotitems):
dist_pt = unit.topt(self.dist)
c = canvas.canvas()
plotitems = [plotitem for plotitem in plotitems if plotitem.gettitle() is not None]
itemspercolumn = (len(plotitems) + self.columns  1) // self.columns
x_pt = 0
while plotitems:
subc = self.subkey.paint(plotitems[:itemspercolumn])
c.insert(subc, [trafo.translate_pt(x_pt, 0)])
x_pt += unit.topt(subc.bbox().width()) + dist_pt
del plotitems[:itemspercolumn]
if self.keyattrs is not None:
newc = canvas.canvas()
newc.draw(c.bbox().enlarged(self.border).path(), self.keyattrs)
newc.insert(c)
c = newc
return c
g = graph.graphxy(width=8, key=columnkey(),
x=axis.linear(min=0, max=2*pi, title="$x$", divisor=pi,
texter=axis.texter.rational(suffix=r"\pi")),
y=axis.linear(title="$y$"))
g.plot(graph.data.function("y=sin(x)", title=r"$\sin(x)$"))
g.plot(graph.data.function("y=cos(x)", title=r"$\cos(x)$"))
g.plot(graph.data.function("y=sin(x+pi)", title=r"$\sin(x+\pi)$"))
g.plot(graph.data.function("y=cos(x+pi)", title=r"$\cos(x+\pi)$"))
g.finish()
g.stroke(g.ygridpath(0))
g.writeEPSfile("piaxis")
I would like to add this to the CVS for 0.8, but I don't really like
the name. Does anybody has a better name for columnkey?
André

by _ _ _ Dr. André Wobst
/ \ \ / ) wobsta@..., http://www.wobsta.de/
/ _ \ \/\/ / PyX  High quality PostScript figures with Python & TeX
(_/ \_)_/\_/ visit http://pyx.sourceforge.net/
