Best way for rotating a matrix of data?

Raphaël Plasson rplasson at
Wed Sep 22 04:38:06 CEST 2010


after some computations, I obtain a 2D matrix of data, in a numpy
array. I can easily plot them using pyplot, and can easily extract
either vertical or horizontal slices by plotting a row or a column of
this matrix. I would like to be able to plot slices form this data
array, but with an arbitrary angle. Thus my question: what is the best
way to do so?

For the moment the solution I am using is to go through image
transformation, using PIL, by a function returning :
In short, I convert the array in an image object, I rotate it, and
then convert it back to an array. Not very clean, rather a work around
than a solution, indeed.

Actually, I more precisely extract my 2D array from much higher
dimensions data (i.e. 10-20 fields of different data in 3 dimensions
of space+1 dimension of time), contained in a hdf5 file. I typically
would like to extract arbitrary slices of any of the fields from the
3+1D space... and I don't really know how this can be simply done. I
can only extract an "orthogonal" 2D space from this space, and rotate
it with the above method.

Is there a more direct way to extract arbitrary slices directly from
2/3/4D arrays? Which python modules would be able to do the job?

Thank you,


More information about the Python-list mailing list