There are a few ways to do that depending on exactly what you want.

From your script, you may just clip your image.

im = imshow(Z, extent=(-1, 1, -1, 1))
im.set_clip_path(Circle((0,0),1, transform=ax.transData))

(Note the use of extent keyword in imshow)

Or,

You can use polar coordinate with pcolormesh for image display. But
your data need to be defined in the polar coordinate, unlike your
script.

# function defined in polar coordinate
def func5(theta, r):
    y = r*np.sin(theta)
    theta=np.arcsin(y)
    return np.cos(theta)


R=1.
n_theta, n_r = 360, 100

# cooridnates of the mesh
theta = np.linspace(0, 2*np.pi, n_theta+1)
r = np.linspace(0., R, n_r + 1)

dr, dtheta = r[1]-r[0], theta[1]-theta[0]

# cooridnate for the data point
theta_d = np.arange(dtheta/2., 2*np.pi, dtheta)
r_d = np.arange(dr/2., R, dr)


TT, RR = meshgrid(theta_d, r_d)
Z = func5(TT, RR)

ax=subplot(1,1,1, projection="polar", aspect=1.)
ax.pcolormesh(theta, r, Z)

-JJ






On Mon, Apr 6, 2009 at 6:35 AM, Lorenzo Isella <lorenzo.ise...@gmail.com> wrote:
> Hello,
> So maybe a couple of images can help.
> Using the code
>
>
> #!/usr/bin/env python
> """
> See pcolor_demo2 for a much faster way of generating pcolor plots
> """
> from __future__ import division
> from pylab import *
>
> def func3(x,y):
>   return (1- x/2 + x**5 + y**3)*exp(-x**2-y**2)
>
>
> def func4(x,y):
>   theta=arcsin(y)
>   return cos(theta)
>
>
> # make these smaller to increase the resolution
> dx, dy = 0.05, 0.05
>
> x = arange(-1.0, 1.0, dx)
> y = arange(-1.0, 1.0, dy)
> X,Y = meshgrid(x, y)
>
> Z = func4(X, Y)
>
> print "Z is, ", Z
>
> ax = subplot(111)
> im = imshow(Z, cmap=cm.jet)
> #im.set_interpolation('nearest')
> #im.set_interpolation('bicubic')
> im.set_interpolation('bilinear')
> #ax.set_image_extent(-3, 3, -3, 3)
>
> show()
>
> I can get the attached image.png, but what I am really after is
> image2.png (the same quantity plotted on a circular domain!). How can
> I achieve that (without using scissors on an existing image?).
> This is what I meant from start.
> Cheers
>
> Lorenzo
>
>
>
>
> 2009/4/3 Jae-Joon Lee <lee.j.j...@gmail.com>:
>> I'm afraid that I'm still confused and there seems to be not much
>> thing I can help..
>>
>> You're considering a circle, but you already have your function in a
>> cartesian coordinate. I'm not sure why you can't just plot in a
>> cartesian coordinate? (in other words, what is wrong with your
>> original script?)
>>
>> There is an "set_image_extent" call in your original script (although
>> commented out). Maybe what you're trying to do is simply
>>
>>  im = imshow(Z, cmap=cm.jet, extent=(-3, 3, -3, 3))
>>
>> I'm not sure it would be relevant, but if you have your function or
>> data in  (r, theta) coordinate, one simple way is just to use the
>> polar axes with pcolormesh method.
>>
>>  n_theta, n_r = 100, 50
>>  theta = np.linspace(0, 2*np.pi, n_theta+1)
>>  r = np.linspace(0., 1., n_r + 1)
>>  data = np.arange(0., n_theta*n_r).reshape(n_r, n_theta)
>>  ax=subplot(1,1,1, projection="polar", aspect=1.)
>>  ax.pcolormesh(theta, r, data)
>>
>>
>>
>> -JJ
>>
>
>
>
> --
> Life is what happens to you while you're busy making other plans.
>

------------------------------------------------------------------------------
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to