Hi Andr=C3=A9,
Am Mittwoch, den 01.08.2007, 17:27 +0200 schrieb Andre Wobst:
> Hi all,
>=20
> On 25.07.07, BK wrote:
> > > is there any way to directly plot scipy/numpytype arrays? I am readi=
ng
> > my data using the scipy.array_import.read_array() method and then doing
> > some data manipulations based on the scipy arrays.
> > Before plotting I currently write the data from the arrays into a list
> > which can be read by the pyx.graph.graphxy.plot() method. Would it be
> > possible to add scipytype array data to the plot() method of a graph?
>=20
> Sure ... and its even trivial to implement new data providers for pyx.
> (Let me call instances of the classes defined in pyx.graph.data to be
> "data providers".) Well, there are some nontrivial features in the
> data providers. Think of functions, where the range the function is
> evaluated may depend on the range of the corresponding axes. But those
> things really are advanced features and simple data providers don't
> need to deal with such stuff at all.
>=20
> The point is that (1) I do not know what people want and need and (2)
> I'm not an scipy user at all. OTOH I do know that pyx.graph.data
> really is very limited in terms of manipulating data. And it's also
> slow. So we just need to find out what's needed for all of you, guys,
> and I'll try to add an appropriate data provider to PyX. I'm sure
> thats better than reimplementing features found in scipy. It's fine
> that PyX comes with some useful data providers, since PyX users really
> should not need to scipy in the first place. But those of you who are
> beeing happy scipy users should get the power out of scipy + PyX most
> easily. Ok, enough blah, blah ...
>=20
> There is the pyx.graph.data.list class, which takes a list of lists
> and an columns dictionary. For example:
>=20
> d =3D pyx.graph.data.list([[1, 2], [3, 4]], x=3D1, y=3D2)
>=20
> (and than proceed with g.plot(d) ...)
>=20
> This means that you have two points, the first one with x=3D1 and y=3D2
> and the second one with x=3D3 and y=3D4.
>=20
> I've just tried to use read_array and provide a useful "adapter" for
> PyX. This looks the following:
>=20
> from scipy.io import read_array
> from pyx import *
>=20
> class lists(graph.data._data):
>=20
> defaultstyles =3D [graph.style.symbol()]
>=20
> def __init__(self, title=3D"user provided lists", **columns):
> self.columns =3D columns
> self.columnnames =3D columns.keys()
> self.title =3D title
>=20
> d =3D read_array("scipytest.dat")
> g =3D graph.graphxy(width=3D10)
> g.plot(lists(x=3Dd[0], y=3Dd[1]))
> g.writeEPSfile("scipytest")
>=20
Your little adapter does the trick, thanks a lot!
It's indeed very simple and after seeing your solution and looking again
at the 'list' class I feel a little stupid for not figuring it out
myself. I don't know about other scipy users (if there are any others
using PyX, after all scipy comes with its own plotting module
'matplotlib') but for me it's exactly what I needed.
Rather than renaming the old 'list' class you could add the above class
as something like a 'vector' or 'array' class.
Thanks again!
Benedikt
> It's that simple. You really need to understand, that the PyX data
> instances are very thin wrappers and maybe we should even more focus
> on that. While I kind of dislike the above notation (d[0] and d[1] are
> completely independed) and thus I focused on "points" in
> pyx.graph.data.list, why not just add the lists class to PyX as well?
> Maybe the name is not perfect. Well, "list" was not a good idea at
> all ... I could think of renaming the old "list" to "points" and
> adding the "lists" class as shown above. I know that'll break quite
> some code and we could add some deprecated "list =3D points" to
> pyx.graph.data, but let's keep the focus: Does the signature of the
> lists class shown above match the scipy users needs? Or should it look
> differently?
>=20
>=20
> Andr=C3=A9
>=20
