|
From: Andre W. <and...@ph...> - 2003-04-16 10:53:01
|
Hi Ralf,
On 15.04.03, Ralf Utermann wrote:
> What I found out from examples and docs is that I have to
> add a lineattrs argument like:
>
> g.plot( graph.data("bd.dat", x=0, y=3, title = "Sys" ),
> graph.symbol(lineattrs=canvas.linestyle.dashed) )
>
> to the 3 g.plot() calls. The problem is, that the symbols don't
> iterate anymore. I ended up setting this explicitely on every
> call:
>
> g.plot(graph.data("bd.dat", x=0, y=3, title = "X" ),
> graph.symbol( symbol=graph.changesymbol.circle(),lineattrs=canvas.linestyle.dashed))
> g.plot(graph.data("bd.dat", x=0, y=4, title = "Y" ),
> graph.symbol( symbol=graph.changesymbol.square(),lineattrs=canvas.linestyle.dashed))
> g.plot(graph.data("bd.dat", x=0, y=5, title = "Z" ),
> graph.symbol(symbol=graph.changesymbol.triangle(),lineattrs=canvas.linestyle.dashed))
>
> I assume, there is a more elegant way to do this; any ideas?
Yes, of course. The idea of iterateable style attributes is, that you
use them for plotting several data sets. The easiest way to do that is
to apply the iterable style to a list of data instances. The example
above would become:
g.plot([graph.data("bd.dat", x=0, y=3, title="X"),
graph.data("bd.dat", x=0, y=4, title="Y"),
graph.data("bd.dat", x=0, y=5, title="Z")],
graph.symbol(symbol=graph.changesymbol.circle(), lineattrs=canvas.linestyle.dashed))
Now the style gets iterated over the list of data you've plugged in.
However, if you do not specify any style at all, the defaultstyle of
the provided data is used within the subsequent plot calls. Thus, the
iteration process is performed as well.
You may now think of another solution:
s = graph.symbol(symbol=graph.changesymbol.circle(), lineattrs=canvas.linestyle.dashed))
g.plot(graph.data("bd.dat", x=0, y=3, title = "X" ), s)
g.plot(graph.data("bd.dat", x=0, y=4, title = "Y" ), s)
g.plot(graph.data("bd.dat", x=0, y=5, title = "Z" ), s)
Well, I've noticed right now, that this doesn't work like expected
(which I immediately added to my TODO list). When doing this, you have
to pass the result of s.iterate() in subsequent plot calls (except for
the first) right now. For future version I'll change that, because it
doesn't fit to my understanding of how this iteration process should
be kicked off. However, the iteration behaviour of the defaultstyle
should be understood that way, that there is a magic behind the scene
which iterates the style when it is applied several times.
> And, BTW, it was not so easy to see that symbols are handled via
> graph and lines via canvas. For me, the symbols and lines which
> make the plot are objects on the same level -- I would always
> assume them to be handled by the same class, which apparently PyX
> does not do. Could someone elaborate on this?
There is a simple reason for that. The symbol itself is a method (or
some iteration wrapper around a method). Those symbol methods just
return a path and are defined as graph.symbol.cross() and so on. You
can plug the in directly. In your example above where you didn't use
the iteration at all you could have used graph.symbol.cross() etc. The
iterators around those methods are named graph.changesymbol.circle()
etc. (Note: You have to instantiate those iterators manually to always
get a new instance of the iterators). This hole business is very
different from stroke/fill attributes. lineattrs (and symbolattrs as
well) is a list of instances of classes derived from PathStyle. They
are right now defined in the canvas module.
I agree, that the difference between symbol and lineattrs might be
obscure to the user. Also the question when an instantiation of some
attribute is needed or not (is this attribute a class or already an
instance) might be very confusing (on the other hand for iterators an
explicit instantiation is difficult to overcome). I'm not quite sure
how to improve this situation.
André
PS: I'm sorry about my late responses all the time due to some MTA
problems.
--
by _ _ _ And...@Ph...
/ \ \ / ) http://www.physik.uni-augsburg.de/~wobsta/
/ _ \ \/\/ / PyX - High quality PostScript figures with Python & TeX
(_/ \_)_/\_/ visit http://pyx.sourceforge.net/
|