Issues with clockwise polar plot

I have a list of values representing radius (r) and another representing angles (theta). I am trying to make a polar plot with North as 0 deg, East as 90 deg and so on.

import matplotlib.pyplot as plt 
import numpy as np

theta = [87.23008557164445, 100.26076015446364, 78.71990232378403, 136.34914122677247, 103.6118957767244, 108.8898592700267, 93.2079887669754]

r = [9.672704455052727, 5.747648969819628, 7.8846103848102835, 3.924182947507153, 5.631744483153131, 7.051601437489786, 2.2619972761713196]

colors = ['#c96253', '#e6b065', '#59c752', '#52c7bb', '#5260c7', 'w', 'k']

fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})
ax.set_theta_direction(-1)
ax.set_theta_zero_location('N')

for i in range(0, len(r)):
    ax.vlines(theta[i], 0, r[i], colors=colors[i], zorder=3)

The angles in the list does not correspond to what is plotted. Does anyone know how to solve it?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You need to put the theta parameter in radians. You can use math.radians() to do this.

import matplotlib.pyplot as plt 
import numpy as np
import math

theta = [87.23008557164445, 100.26076015446364, 78.71990232378403, 136.34914122677247, 103.6118957767244, 108.8898592700267, 93.2079887669754]

r = [9.672704455052727, 5.747648969819628, 7.8846103848102835, 3.924182947507153, 5.631744483153131, 7.051601437489786, 2.2619972761713196]

colors = ['#c96253', '#e6b065', '#59c752', '#52c7bb', '#5260c7', 'w', 'k']

fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})
ax.set_theta_direction(-1)
ax.set_theta_zero_location('N')

for i in range(0, len(r)):
    ax.vlines(math.radians(theta[i]), 0, r[i], colors=colors[i], zorder=3)

Output

Issues with clockwise polar plot


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x