Home > Software design >  Polar plots in python
Polar plots in python

Time:12-11

I'm trying to plot antenna pattern in python. I have the measured theta vs. radius readings in a csv file. However, when I try the following code

import numpy  as np
import matplotlib.pyplot as plt

gain_on = np.loadtxt('patterne.txt')


#------------------------------------------------------------------------


theta = gain_on[:, 0]
r = gain_on[:, 3]

fig1 = plt.figure()
ax1 = fig1.add_axes([0.1,0.1,0.8,0.8],polar=True)
ax1.set_rlim(-50,0)
#ax1.set_yticks(np.arange(-2,2,0.5))
ax1.plot(theta,r)
plt.show()

I get this output python polar plot

The expected plot is expected plot How do I get the expected plot in python?

CodePudding user response:

Change your units for theta from degrees to radians:

theta = numpy.deg2rad(gain_on[:,0])

In the examples for Matplotlib polar plots they always use angle in radians. e.g. https://matplotlib.org/stable/gallery/pie_and_polar_charts/polar_demo.html

  • Related