polar graph

Hi, i'm wondering if there is an easy way to fill the background in a polar
graph with a specific color. If I were making a pie graph, it'd be
something like: pie([70,20,10]), where the first 70% is green, the next 20,
yellow, and the last 10, red. I've been experimenting with polar graphs
using some random data and i've gotten close to what I want, but it'd be
neat to have a color in the background. Here's what I have now. it's a
polar scatter plot, much like what is found in the gallery, but with a few
changes.

from pylab import *
import numpy as np

snp=[]
for i in range(0,65):
    snp.append(np.random.randint(35,122))

tempTuple=array(snp)

r = tempTuple/10
theta = ((tempTuple*2.9508)*pi)/180
area = r**2*(tempTuple/5.4)
colors = theta
ax = subplot(111, polar=True)
c = scatter(theta, r, c=colors, s=area)
c.set_alpha(0.75)
show()

···

--
View this message in context: http://www.nabble.com/polar-graph-tp22230232p22230232.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

I made a little more progress, but i'm not sure i'm doing this the right way.
Suggestions?

from pylab import *
import numpy as np

#generate random temperature data
snp=[]
for i in range(0,65):
    snp.append(np.random.randint(35,122))

#hide the labels. I don't want them.
rc('xtick', labelsize=0)
rc('ytick', labelsize=0)

fig=figure(figsize=(8,8),facecolor='0.0')

ax = fig.add_subplot(111,polar=True,frameon=False)
tempTuple=array(snp)
r = tempTuple/10
theta = ((tempTuple*2.9508)*pi)/180
area = r**2*(tempTuple/5.4)
colors = theta

#this is the fancy green,yellow,red background
#it's actually a scatter plot that sits behind (zorder)
#of the rest of the scatter plots.

#radius
r1 = 0.7 # 20%
r2 = r1 + 0.2 # 40%

# define some sizes of the scatter marker
sizes = [55000]
x = [0] + np.cos(np.linspace(0, 2*math.pi*r1, 100)).tolist()
y = [0] + np.sin(np.linspace(0, 2*math.pi*r1, 100)).tolist()
xy1 = zip(x,y)

x = [0] + np.cos(np.linspace(2*math.pi*r1, 2*math.pi*r2, 100)).tolist()
y = [0] + np.sin(np.linspace(2*math.pi*r1, 2*math.pi*r2, 100)).tolist()
xy2 = zip(x,y)

x = [0] + np.cos(np.linspace(2*math.pi*r2, 2*math.pi, 100)).tolist()
y = [0] + np.sin(np.linspace(2*math.pi*r2, 2*math.pi, 100)).tolist()
xy3 = zip(x,y)

ax.scatter([0,0,0], [0,0,0], marker=(xy1,0), s=sizes,
facecolor='green',alpha=.25,zorder=1)
ax.scatter([0,0,0], [0,0,0], marker=(xy2,0), s=sizes, facecolor='yellow'
,alpha=.25,zorder=1)
ax.scatter([0,0,0], [0,0,0], marker=(xy3,0), s=sizes,
facecolor='red',alpha=.25,zorder=1)
ax.scatter(theta, r, c=colors, s=area,zorder=2)
ax.grid(False)

show()

···

--
View this message in context: http://www.nabble.com/polar-graph-tp22230232p22234721.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

I recommend you to use the Wedge class in matplotlib.patches.

from matplotlib.patches import Wedge

# draw a wedge in the axes coordinate. (0.5, 0.5) in axes coordinate
corresponds to (0,0) in polar coordinate.
trans = ax.transAxes
center, R = (0.5, 0.5), 0.5
twopi=360.
pie1 = Wedge(center, R, 0, r1*twopi, fc="g")
pie2 = Wedge(center, R, r1*twopi, r2*twopi, fc="y")
pie3 = Wedge(center, R, r2*twopi, twopi, fc="r")

for mypie in [pie1, pie2, pie3]:
   mypie.set_transform(trans)
   mypie.set_alpha(0.25)
   mypie.set_ec("none")
   ax.add_patch(mypie)

-JJ

···

On Thu, Feb 26, 2009 at 5:00 PM, bubye <joe.hrbek@...287...> wrote:

I made a little more progress, but i'm not sure i'm doing this the right way.
Suggestions?

from pylab import *
import numpy as np

#generate random temperature data
snp=[]
for i in range(0,65):
snp.append(np.random.randint(35,122))

#hide the labels. I don't want them.
rc('xtick', labelsize=0)
rc('ytick', labelsize=0)

fig=figure(figsize=(8,8),facecolor='0.0')

ax = fig.add_subplot(111,polar=True,frameon=False)
tempTuple=array(snp)
r = tempTuple/10
theta = ((tempTuple*2.9508)*pi)/180
area = r**2*(tempTuple/5.4)
colors = theta

#this is the fancy green,yellow,red background
#it's actually a scatter plot that sits behind (zorder)
#of the rest of the scatter plots.

#radius
r1 = 0.7 # 20%
r2 = r1 + 0.2 # 40%

# define some sizes of the scatter marker
sizes = [55000]
x = [0] + np.cos(np.linspace(0, 2*math.pi*r1, 100)).tolist()
y = [0] + np.sin(np.linspace(0, 2*math.pi*r1, 100)).tolist()
xy1 = zip(x,y)

x = [0] + np.cos(np.linspace(2*math.pi*r1, 2*math.pi*r2, 100)).tolist()
y = [0] + np.sin(np.linspace(2*math.pi*r1, 2*math.pi*r2, 100)).tolist()
xy2 = zip(x,y)

x = [0] + np.cos(np.linspace(2*math.pi*r2, 2*math.pi, 100)).tolist()
y = [0] + np.sin(np.linspace(2*math.pi*r2, 2*math.pi, 100)).tolist()
xy3 = zip(x,y)

ax.scatter([0,0,0], [0,0,0], marker=(xy1,0), s=sizes,
facecolor='green',alpha=.25,zorder=1)
ax.scatter([0,0,0], [0,0,0], marker=(xy2,0), s=sizes, facecolor='yellow'
,alpha=.25,zorder=1)
ax.scatter([0,0,0], [0,0,0], marker=(xy3,0), s=sizes,
facecolor='red',alpha=.25,zorder=1)
ax.scatter(theta, r, c=colors, s=area,zorder=2)
ax.grid(False)

show()

--
View this message in context: http://www.nabble.com/polar-graph-tp22230232p22234721.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users