|
From: Auré G. <aur...@ya...> - 2011-03-10 14:40:14
|
Dear all,
Once again, I turn for help.
I'm trying to plot a polar image using colormap values for the theta values and
increasing alpha values along the radius.
I do this using imshow passing the rgba tuple at each pixel position which works
very nicely with rectangular axes, but fails to display using polar axes (see
code below).
As usual, I've done a fair bit of digging to find where the problem is and
whether I could make out an alternate solution but haven't managed to come
through. I've tried using pcolormesh but I don't see how to pass the rgba tuple
Can anyone point me in the right direction.
I'm using matplotlib 1.0.1 and Python 2.4
Cheers,
Auré
------
import matplotlib as mpl
from matplotlib import pylab
import numpy as np
#build custom colormap
cm_sym =customfunc()
#define mesh grid
theta = np.arange(0.,2.*math.pi+2.*math.pi/9,2.*math.pi/9)
r = np.arange(0,1.1,0.1)
X,Y = np.meshgrid(r,theta)
#define rgba array
polarcolorseq = mpl.cm.ScalarMappable(cmap=cm_hsvsym).to_rgba(Y)
#set an increasing alpha value along the radius
polarcolorseq[:,:,-1] = [list(np.arange(0,1.1,.1))]*10
pylab.figure(figsize=(10,5),dpi=100,facecolor='white')
#display using rectangular axis
ax = pylab.subplot((121),axisbg='k')
ax.imshow(np.flipud(np.swapaxes(polarcolorseq,0,1)))
#display using polar axis
ax2 = pylab.subplot((122),axisbg='k',projection='polar') #also tried with
polar=True
ax2.imshow(np.flipud(np.swapaxes(polarcolorseq,0,1)))
pylab.draw()
|
|
From: Benjamin R. <ben...@ou...> - 2011-03-10 17:43:52
|
On Thu, Mar 10, 2011 at 8:40 AM, Auré Gourrier <aur...@ya...>wrote: > Dear all, > > Once again, I turn for help. > I'm trying to plot a polar image using colormap values for the theta values > and increasing alpha values along the radius. > I do this using imshow passing the rgba tuple at each pixel position which > works very nicely with rectangular axes, but fails to display using polar > axes (see code below). > As usual, I've done a fair bit of digging to find where the problem is and > whether I could make out an alternate solution but haven't managed to come > through. I've tried using pcolormesh but I don't see how to pass the rgba > tuple > Can anyone point me in the right direction. > I'm using matplotlib 1.0.1 and Python 2.4 > > Cheers, > > Auré > > It appears that imshow() (and matshow()) do not support non-rectilinear axes. I don't know if this is a bug or if there is no way to make it support polar projections. Hopefully, someone else more knowledgable could chime in on this. I am also not exactly sure how to accomplish what you want using pcolor. A really slow, painful way would be to pcolor each row with the rest masked out, setting the alpha value for that row. I have long wondered if the alpha kwarg in various functions could be improved by allowing array values and take advantage of numpy broadcasting. Ben Root |
|
From: Auré G. <aur...@ya...> - 2011-03-10 22:01:55
|
Thanks, I read some of your previous posts dealing with the pcolor and tried
this route but didn't succeed yet...
I really agree with you on the interest of having an option to pass an array
rather than value for the alpha keyword !
________________________________
De : Benjamin Root <ben...@ou...>
À : Auré Gourrier <aur...@ya...>
Cc : mat...@li...
Envoyé le : Jeu 10 mars 2011, 18h 43min 31s
Objet : Re: [Matplotlib-users] alternative to imshow with polar axes ?
On Thu, Mar 10, 2011 at 8:40 AM, Auré Gourrier <aur...@ya...>
wrote:
Dear all,
>
>Once again, I turn for help.
>I'm trying to plot a polar image using colormap values for the theta values and
>increasing alpha values along the radius.
>I do this using imshow passing the rgba tuple at each pixel position which works
>very nicely with rectangular axes, but fails to display using polar axes (see
>code below).
>
>As usual, I've done a fair bit of digging to find where the problem is and
>whether I could make out an alternate solution but haven't managed to come
>through. I've tried using pcolormesh but I don't see how to pass the rgba tuple
>Can anyone point me in the right direction.
>I'm using matplotlib 1.0.1 and Python 2.4
>
>Cheers,
>
>Auré
>
>
It appears that imshow() (and matshow()) do not support non-rectilinear axes. I
don't know if this is a bug or if there is no way to make it support polar
projections. Hopefully, someone else more knowledgable could chime in on this.
I am also not exactly sure how to accomplish what you want using pcolor. A
really slow, painful way would be to pcolor each row with the rest masked out,
setting the alpha value for that row. I have long wondered if the alpha kwarg
in various functions could be improved by allowing array values and take
advantage of numpy broadcasting.
Ben Root
|
|
From: Auré G. <aur...@ya...> - 2011-03-15 16:26:00
|
Really no one to point me in the right direction ?
This is really important, I'm trying to wrap up a publication and this is the
only element missing...
________________________________
De : Auré Gourrier <aur...@ya...>
À : mat...@li...
Envoyé le : Jeu 10 mars 2011, 15h 40min 04s
Objet : [Matplotlib-users] alternative to imshow with polar axes ?
Dear all,
Once again, I turn for help.
I'm trying to plot a polar image using colormap values for the theta values and
increasing alpha values along the radius.
I do this using imshow passing the rgba tuple at each pixel position which works
very nicely with rectangular axes, but fails to display using polar axes (see
code below).
As usual, I've done a fair bit of digging to find where the problem is and
whether I could make out an alternate solution but haven't managed to come
through. I've tried using pcolormesh but I don't see how to pass the rgba tuple
Can anyone point me in the right direction.
I'm using matplotlib 1.0.1 and Python 2.4
Cheers,
Auré
------
import matplotlib as mpl
from matplotlib import pylab
import numpy as np
#build custom colormap
cm_sym =customfunc()
#define mesh grid
theta = np.arange(0.,2.*math.pi+2.*math.pi/9,2.*math.pi/9)
r = np.arange(0,1.1,0.1)
X,Y = np.meshgrid(r,theta)
#define rgba array
polarcolorseq = mpl.cm.ScalarMappable(cmap=cm_hsvsym).to_rgba(Y)
#set an increasing alpha value along the radius
polarcolorseq[:,:,-1] = [list(np.arange(0,1.1,.1))]*10
pylab.figure(figsize=(10,5),dpi=100,facecolor='white')
#display using rectangular axis
ax = pylab.subplot((121),axisbg='k')
ax.imshow(np.flipud(np.swapaxes(polarcolorseq,0,1)))
#display using polar axis
ax2 = pylab.subplot((122),axisbg='k',projection='polar') #also tried with
polar=True
ax2.imshow(np.flipud(np.swapaxes(polarcolorseq,0,1)))
pylab.draw()
|
|
From: Michael D. <md...@st...> - 2011-03-15 17:06:24
|
Can you provide a standalone example? This below is missing some imports and there are some mystery variables. Mike On 03/15/2011 12:25 PM, Auré Gourrier wrote: > import matplotlib as mpl > from matplotlib import pylab > import numpy as np > > #build custom colormap > cm_sym =customfunc() > > #define mesh grid > theta = np.arange(0.,2.*math.pi+2.*math.pi/9,2.*math.pi/9) > r = np.arange(0,1.1,0.1) > X,Y = np.meshgrid(r,theta) > > #define rgba array > polarcolorseq = mpl.cm.ScalarMappable(cmap=cm_hsvsym).to_rgba(Y) > #set an increasing alpha value along the radius > polarcolorseq[:,:,-1] = [list(np.arange(0,1.1,.1))]*10 > > pylab.figure(figsize=(10,5),dpi=100,facecolor='white') > > #display using rectangular axis > ax = pylab.subplot((121),axisbg='k') > ax.imshow(np.flipud(np.swapaxes(polarcolorseq,0,1))) > > #display using polar axis > ax2 = pylab.subplot((122),axisbg='k',projection='polar') #also > tried with polar=True > ax2.imshow(np.flipud(np.swapaxes(polarcolorseq,0,1))) > > pylab.draw() -- Michael Droettboom Science Software Branch Space Telescope Science Institute Baltimore, Maryland, USA |