how to read a file contains x y z coordinate and plot it as 3D figure

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

how to read a file contains x y z coordinate and plot it as 3D figure

zhixiu li
Hi ALL,
Dear All,
I have a dataset like this (in data.txt)
1 0 0
2 0 0
1 2 3
1 2 3.2
...
the 1st column is x and the second col is y. the last column is the
attribute of this point.

I want to make a 3 D plot for each points(Z will the attribute value).
How do I read this data file to mayavi? Thank you very much!

I can draw a color plot in matlab and save it as png file and the read this
png file then make a 3D plot by VTK. But I think there should be easier way
to make a 3D plot.

Thank you!
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: how to read a file contains x y z coordinate and plot it as 3D figure

Gael Varoquaux
Hi,

On Sat, Apr 21, 2012 at 03:23:52PM -0400, zhixiu li wrote:
> I have a dataset like this (in data.txt)
> 1 0 0
> 2 0 0
> 1 2 3
> 1 2 3.2
> ...
> the 1st column is x and the second col is y. the last column is the
> attribute of this point.

> I want to make a 3 D plot for each points(Z will the attribute value).
> How do I read this data file to mayavi? Thank you very much!

The first thing that you need to do is to read the data in Python. For
this I would use the numpy module, with the loadtxt function.

Once you have done this, you have a 3D array with the 2 first columns
giving you the indices (x, y), and the last one the values (z).

You need to get this data in a 2D array where the position in the array
is encoded by x, y data, and the values by z.

One way is to create such an empty array, and then assign the z values in
it (this is standard array manipulation using numpy, if you need an
introduction, check out
http://scipy-lectures.github.com/intro/numpy/numpy.html).

Once you have this 2D array, you can use Mayavi's mlab.surf to plot it:
http://github.enthought.com/mayavi/mayavi/auto/mlab_helper_functions.html#mayavi.mlab.surf

HTH,

Gaƫl
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev