Re: [PyX-user] arrange key entries in rows and columns

Hi André,
On 13.04.05, Andre Wobst wrote:
> I still want to add this nice litte feature to the PyX core. However
> the name columnkey gets a "-1" from me. How about multicolkey. This
> would be along the lines of LaTeX's multicol package. Or should we go
> for the full written name: multicolumnkey? I'm not sure ...
I'd prefer multicolumkey. But before you check it in: why don't we just
add the multicolumn feature to the key class by extending the
constructor by another parameter columns (defaulting to 1)?
Jörg

Thread view

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi folks,
eventually I dare to post on this list ;-)
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?
Cheers, Micha
- --
- --------------------------------------------------------------------
Michael Strass * mailto:michael.strass@...
Lehrstuhl fuer Theoretische Physik I * Universitaetsstr. 1/Geb. Nord
D-86135 Augsburg * Tel.: +49-821-598-3230
- --------------------------------------------------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCUs0dnDFQHBNYmYcRAvMlAJ94L2AoUGwF9+y98yxULCz6tpspQACeNkKR
7oKp/TMRKjmY3ucAdUo79KE=
=3Iz2
-----END PGP SIGNATURE-----

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/

+1 for multicolumnkey
+0 for multicolkey
Andrea.
On 13 Apr 2005, at 14:13, Andre Wobst wrote:
> I still want to add this nice litte feature to the PyX core. However
> the name columnkey gets a "-1" from me. How about multicolkey. This
> would be along the lines of LaTeX's multicol package. Or should we go
> for the full written name: multicolumnkey? I'm not sure ...

Hi André,
On 13.04.05, Andre Wobst wrote:
> I still want to add this nice litte feature to the PyX core. However
> the name columnkey gets a "-1" from me. How about multicolkey. This
> would be along the lines of LaTeX's multicol package. Or should we go
> for the full written name: multicolumnkey? I'm not sure ...
I'd prefer multicolumkey. But before you check it in: why don't we just
add the multicolumn feature to the key class by extending the
constructor by another parameter columns (defaulting to 1)?
Jörg

Hi,
On 13.04.05, Joerg Lehmann wrote:
> I'd prefer multicolumkey. But before you check it in: why don't we just
> add the multicolumn feature to the key class by extending the
> constructor by another parameter columns (defaulting to 1)?
Damn, you're right! In my example I extended the existing graph key by
efficiently using the old code. Its nice to be able to do that. But in
the end, there is no problem in extending it in-place ... ;-)
André
--
by _ _ _ Dr. André Wobst
/ \ \ / ) wobsta@..., http://www.wobsta.de/
/ _ \ \/\/ / PyX - High quality PostScript figures with Python & TeX
(_/ \_)_/\_/ visit http://pyx.sourceforge.net/

Hi Gert,
On 13.04.05, Gert Ingold wrote:
> > I'd prefer multicolumkey. But before you check it in: why don't we just
> ^
> I would prefer it with an additional 'n' ;-)
Oh, sure, this was just meant to be an abbreviatio :-)
> But seriously: I kind of like Andres argument that multicolkey relates nicely
^ André's
> to the multicol package.
Anyway, this problem has been solved by not introducing this class at
all.
Jörg