Loading...

matplotlib-users@lists.sourceforge.net

[Prev] Thread [Next]  |  [Prev] Date [Next]

Re: [Matplotlib-users] Rotating in imshow Thomas Robitaille Fri Mar 13 15:01:34 2009

It looks like rotation/translation should be easy to do with Affine2D,  
so I tried using it, but I can't seem to get it to work as expected -  
here is an example of how I am using it:

import numpy as np
from matplotlib.pyplot import *
from matplotlib.transforms import Affine2D

im = np.random.random((10,10))
tr = Affine2D().rotate_deg(45.)

fig = figure()
ax = fig.add_subplot(111)
ax.imshow(im,transform=tr)
fig.canvas.draw()

Am I doing something wrong?

Thanks!

Thomas

On Mar 13, 2009, at 5:20 PM, Andrew Straw wrote:

> Eric Firing wrote:
>> Thomas Robitaille wrote:
>>> Hello,
>>>
>>> I was wondering whether there is a way to rotate a grayscale/
>>> colorscale when using imshow.
>>>
>>> I have been using PGPLOT (a fortran/c plotting library) for many  
>>> years
>>> now, and the equivalent to imshow is called PGGRAY (or PGIMAG).  
>>> One of
>>> the arguments this function takes is a 6-element array TR which is a
>>> transformation matrix. From the PGPLOT documentation:
>>>
>>> "The transformation matrix TR is used to calculate the world
>>> coordinates of the center of the "cell" that represents each array
>>> element. The world coordinates of the center of the cell  
>>> corresponding
>>> to array element A(I,J) are given by:
>>> X = TR(1) + TR(2)*I + TR(3)*J
>>> Y = TR(4) + TR(5)*I + TR(6)*J"
>>
>> You could do this with the Axes.pcolormesh method.  You could start  
>> with
>> an unrotated grid (generated by meshgrid, for example), apply your
>> rotation, and use that transformed grid in pcolormesh.  Note that
>> pcolormesh requires the grid for the cell boundaries, not centers.
>>
>
> It should work with imshow() as well if you can set the affine  
> component
> of the transform to the desired values. Which it looks like you can in
> Affine2D(). (The affine matrix is the elements of TR listed above, it
> appears.)
>
> I have not tried to do this, however -- just saying that I think it's
> possible.
>
> -Andrew


------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Matplotlib-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users