Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

polar plot fixed

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading