Discussion:
Matplotlib Polar Plot Angles/Axes
afrogazer
2008-09-26 17:41:53 UTC
Permalink
I am creating a wind rose using a polar bar plot bu the points do not
seem to align to the correct angles. Here is the sample code I am
using. I can't seem to see anything in the API on how to set the
angles.

Any ideas anybody?

Thanks.

from pylab import *

angles = arange(0,360,45)
data = [18, 11, 11, 17, 39, 43, 25, 9]

fig = figure(figsize=(8,8))
title('Wind Speed/Direction Frequency.', fontsize=13)
ax = fig.add_subplot(111)
fig.add_axes(([0.15,0.15,0.725,0.725]), polar=True)
labels = arange(0,360,22.5)
lines = arange(0,360,22.5)
ax.axis('off')
bar(angles, data, alpha=0.75, align='center', linewidth=0)

show()
afrogazer
2008-09-26 20:33:42 UTC
Permalink
In my rush I seem to have overlooked that, maybe because it's Friday
afternoon. Converting the degrees to radians fixed it:

rad_angles = [elem*(pi/180) for elem in angles]

Thanks,
afrogazer
2008-09-26 21:43:47 UTC
Permalink
Post by afrogazer
In my rush I seem to have overlooked that, maybe because it's Friday
rad_angles = [elem*(pi/180) for elem in angles]
Thanks,
One other caveat, some of the bars may over-lap. To prevent this, the
width can be set by converting it to radians too:

w = 45*pi/180
bar(angles, data, alpha=0.75, align='center', width=w, linewidth=0)

Now onto plotting clockwise with North(0 deg.) on top....
afrogazer
2008-09-26 21:46:21 UTC
Permalink
On Sep 26, 10:33?pm, afrogazer <justin.k... at gmail.com> wrote:> rad_angles = [elem*(pi/180) for elem in angles]
You are missing some more on a friday afternoon: angles is created by
arange, so it is a numpy array. In that case you simply can do
rad_angles = pi/180 * angles
No need to use list-comprehensions, that is the whole idea about using
these kick-ass objects!
Bas
Thanks! Should have thought of that, Fridays are a drag.
Bas
2008-09-26 21:42:26 UTC
Permalink
Post by afrogazer
rad_angles = [elem*(pi/180) for elem in angles]
You are missing some more on a friday afternoon: angles is created by
arange, so it is a numpy array. In that case you simply can do
rad_angles = pi/180 * angles
No need to use list-comprehensions, that is the whole idea about using
these kick-ass objects!

Bas
Bas
2008-09-26 19:54:11 UTC
Permalink
I only have experience with the matlab version of polar, but my wild
guess is that you have convert your degrees to radians. Go to the
Matplotlib newsgroup if you need any better help.

HTH,
Bas

Loading...