|
From: Andre W. <and...@Ph...> - 2003-02-24 10:13:18
|
Hi Andreas,
On 18.02.03, Andreas Hoffmann wrote:
> I wanted to plot something like
>
> .../\/\.../\/\..../\/\
> in red in blue in red
> .../\/\.../\/\..../\/\
> in blue in red in blue
> .../\/\.../\/\..../\/\
> in red in blue in red
>
> So several columns plotted against the first and each column
> partly in red and partly in blue according to some criteria.
> I did not find a way to plot only parts of a dataset.
>
> Rearranging the dataset would result in multiple listings of
> parts of the first column, is this necessary?
As far as I see, I do not see a better solution right now. But
creating of another column, which holds only part of the data, isn't
that difficult. Unfortunately, there are two ugly bugs in pyx 0.2,
which prevent the following example to run nicely. The patches are
quick and straight forward:
Index: graph.py
===================================================================
RCS file: /cvsroot/pyx/pyx/pyx/graph.py,v
retrieving revision 1.120.2.2
diff -r1.120.2.2 graph.py
2220c2220
< if (height is not None) and (width is None):
---
> elif (height is not None) and (width is None):
Index: data.py
===================================================================
RCS file: /cvsroot/pyx/pyx/pyx/data.py,v
retrieving revision 1.3
diff -r1.3 data.py
74c74
< tree = self.parser.parse(expression)
---
> tree = self.parser.parse(expression, extern=self.extern)
It's really easy to fix it by hand right now. (They are checked into
the cvs head, of course).
Now you can write:
from pyx import *
def step(x, a):
if a > 0:
return x
c = canvas.canvas()
t = c.insert(tex.tex())
g = c.insert(graph.graphxy(t, width = 10))
df = data.datafile("example.dat", extern={"step": step})
df.addcolumn("y1a=step(y1, x-1)")
df.addcolumn("y1b=step(y1, 1-x)")
df.addcolumn("y2a=step(y2, x-1)")
df.addcolumn("y2b=step(y2, 1-x)")
g.plot(graph.data(df, x=1, y="y1a"), graph.line(color.rgb.red))
g.plot(graph.data(df, x=1, y="y1b"), graph.line(color.rgb.blue))
g.plot(graph.data(df, x=1, y="y2a"), graph.line(color.rgb.red))
g.plot(graph.data(df, x=1, y="y2b"), graph.line(color.rgb.blue))
g.finish()
c.writetofile("example")
What is done is to make a step function available in the addcolumn
method by calling an external function (by the way, variables
(e.g. constants) can be made available within the mathematical
expressions the same way). You find a datafile enclosed, where you can
run this example against. (As long as this user list isn't big, I do
not bear in mind the mail size too much.) It might be better to
overlap the values ranges to prevent drawing of gaps --- I suppose,
this can't be done better.
Hope that helps,
André
--
by _ _ _ And...@Ph...
/ \ \ / ) http://www.physik.uni-augsburg.de/~wobsta/
/ _ \ \/\/ / PyX - High quality PostScript figures with Python & TeX
(_/ \_)_/\_/ visit http://pyx.sourceforge.net/
|