[Numpy-discussion] creating mesh data from xyz data
Neil Martinsen-Burrell
nmb@wartburg....
Tue Sep 8 12:51:10 CDT 2009
On 2009-09-08 10:38 , Christopher Barker wrote:
> Giuseppe Aprea wrote:
>> I have some files with data stored in columns:
>>
>> x1 y1 z1
>> x2 y2 z2
>> x3 y3 z3
>> x4 y4 z4
>> x5 y5 z5
>> I usually load data using 3 lists: x, y and z; I wonder if there is
>> any function which is able to take these 3 lists and return the right
>> inputs for matplotlib functions.
>
> There may b e some MPL utilities that help with this, so you may want to
> ask there, but:
>
> What you want to do depends on the nature of your data. If your data is
> on a rectangular structured grid, the you should use your knowledge of
> the data structure to re-create that structure to pass to MPL.
To expand on Chris's very nice explanation, if the data points are in
"raster" order where x1 = x2 = ... = xn and so forth, then you can use
reshape to get your arrays for matplotlib. Here's an example:
>>> x = [1]*5+[2]*5+[3]*5
>>> y = [6,7,8,9,10]*3
>>> z = range(15)
>>> x,y,z
([1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3], [6, 7, 8, 9, 10, 6, 7,
8, 9, 10, 6, 7, 8, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14])
>>> plot_x = np.array(x).reshape(3,5)
>>> plot_y = np.array(y).reshape(3,5)
>>> plot_z = np.array(z).reshape(3,5)
>>> plot_x,plot_y,plot_z
(array([[1, 1, 1, 1, 1],
[2, 2, 2, 2, 2],
[3, 3, 3, 3, 3]]), array([[ 6, 7, 8, 9, 10],
[ 6, 7, 8, 9, 10],
[ 6, 7, 8, 9, 10]]), array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]]))
-Neil
More information about the NumPy-Discussion
mailing list