Logscale on polar plot and alpha as an array

Hi Everyone,

I am currently building an interactive display using matplotlib but I
need the following two options.
1. Setting the r axis of a polar plot to logaritmic scale.
2. Setting alpha for each point individually (preferably by giving
alpha an array of the same length as the data containing a value
between zero and one).
Is this currently possible and if not which alternative approach do
you recommend.
The display needs to plot about a thousand points (using scatter at
the moment) roughly updating every second with older points fading
away (lower value of alpha).

Kind regards,

Pim Schellart

Pim Schellart wrote:

Hi Everyone,

I am currently building an interactive display using matplotlib but I
need the following two options.
1. Setting the r axis of a polar plot to logaritmic scale.
  

axis.set_rscale('log')

2. Setting alpha for each point individually (preferably by giving
alpha an array of the same length as the data containing a value
between zero and one).
Is this currently possible and if not which alternative approach do
you recommend.
  

You can't give alpha an array, but you can create an Nx4 RGBA array (which will let you control the color individually, too). For example:

r = np.arange(0, 3.0, 0.01)
theta = 2*np.pi*r
c = np.zeros((len(r), 4))
c[:,0:3] = (1, 0, 0) # red
c[:,3] = np.arange(0, 1.0, 1.0 / len(r))
ax.scatter(theta, r, c=c, lw=0)

The display needs to plot about a thousand points (using scatter at
the moment) roughly updating every second with older points fading
away (lower value of alpha).
  

Scatter is pretty heavily optimized in the *Agg backends, but not so much in the others. Make sure you are using Agg and IIRC this level of performance should be possible (depending on machine etc., of course).

Mike

···

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Dear Michael,

thank you for the tips.
The color solution works fine but the logarithmic scale has some issues.
It is displayed once but I get the following warning:

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/axes.py:1091:
UserWarning: aspect is not supported for Axes with xscale=linear,
yscale=log
  % (xscale, yscale))

the aspect ratio is also clearly wrong and my polar plot looks like an oval.
I think this warning is not very accurate since for a polar plot the
`y' axis means r and this is supposed to be the same in all (real x,y)
directions.
Also it does not seem to remember it's state (which may be due to me
calling ax.clear() to clear the plot when drawing a new batch of
points) and reverts to lineair.
I use the Qt Agg backend and performance seems to be ok.
I would like to fix the axis and not redraw it on every plot (perhaps
using blitting) if possible.

Kind regards,

Pim Schellart

2010/5/4 Michael Droettboom <mdroe@...86...>:

···

Pim Schellart wrote:

Hi Everyone,

I am currently building an interactive display using matplotlib but I
need the following two options.
1. Setting the r axis of a polar plot to logaritmic scale.

axis.set_rscale('log')

2. Setting alpha for each point individually (preferably by giving
alpha an array of the same length as the data containing a value
between zero and one).
Is this currently possible and if not which alternative approach do
you recommend.

You can't give alpha an array, but you can create an Nx4 RGBA array (which
will let you control the color individually, too). For example:

r = np.arange(0, 3.0, 0.01)
theta = 2*np.pi*r
c = np.zeros((len(r), 4))
c[:,0:3] = (1, 0, 0) # red
c[:,3] = np.arange(0, 1.0, 1.0 / len(r))
ax.scatter(theta, r, c=c, lw=0)

The display needs to plot about a thousand points (using scatter at
the moment) roughly updating every second with older points fading
away (lower value of alpha).

Scatter is pretty heavily optimized in the *Agg backends, but not so much in
the others. Make sure you are using Agg and IIRC this level of performance
should be possible (depending on machine etc., of course).

Mike

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Pim Schellart wrote:

Dear Michael,

thank you for the tips.
The color solution works fine but the logarithmic scale has some issues.
It is displayed once but I get the following warning:

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/axes.py:1091:
UserWarning: aspect is not supported for Axes with xscale=linear,
yscale=log
  % (xscale, yscale))

the aspect ratio is also clearly wrong and my polar plot looks like an oval.
I think this warning is not very accurate since for a polar plot the
`y' axis means r and this is supposed to be the same in all (real x,y)
directions.
  

Can you provide a short, standalone script that reproduces this problem? I don't see it here. What version of matplotlib are you using?

Mike

···

Also it does not seem to remember it's state (which may be due to me
calling ax.clear() to clear the plot when drawing a new batch of
points) and reverts to lineair.
I use the Qt Agg backend and performance seems to be ok.
I would like to fix the axis and not redraw it on every plot (perhaps
using blitting) if possible.

Kind regards,

Pim Schellart

2010/5/4 Michael Droettboom <mdroe@...86...>:
  

Pim Schellart wrote:
    

Hi Everyone,

I am currently building an interactive display using matplotlib but I
need the following two options.
1. Setting the r axis of a polar plot to logaritmic scale.

axis.set_rscale('log')
    

2. Setting alpha for each point individually (preferably by giving
alpha an array of the same length as the data containing a value
between zero and one).
Is this currently possible and if not which alternative approach do
you recommend.

You can't give alpha an array, but you can create an Nx4 RGBA array (which
will let you control the color individually, too). For example:

r = np.arange(0, 3.0, 0.01)
theta = 2*np.pi*r
c = np.zeros((len(r), 4))
c[:,0:3] = (1, 0, 0) # red
c[:,3] = np.arange(0, 1.0, 1.0 / len(r))
ax.scatter(theta, r, c=c, lw=0)
    

The display needs to plot about a thousand points (using scatter at
the moment) roughly updating every second with older points fading
away (lower value of alpha).

Scatter is pretty heavily optimized in the *Agg backends, but not so much in
the others. Make sure you are using Agg and IIRC this level of performance
should be possible (depending on machine etc., of course).

Mike

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA