1

This code plots a particular row of phases given in a NumPy array on a circle of radius 2pi using the matplotlib module.

How can I draw straight lines from the origin(0,0) to these points/phases plotted on the circle?

enter image description here


import numpy as np
import matplotlib.pyplot as plt


def circle(theta):
    
    circle_angle = np.linspace(0, 2*np.pi, 100)
    radius = np.sqrt(1)
    plt.figure()
    fig, ax = plt.subplots(1)

    x1 = radius*np.cos(circle_angle )
    x2 = radius*np.sin(circle_angle )

    plt.plot(x1, x2)
    ax.set_aspect(1)
    plt.grid(linestyle = '--',axis='both')
     
    
    plt.plot(radius*np.cos(theta[:1]),radius*np.sin(theta[:1]),'*')  
  
theta = np.array([[1, 2.3, 3,4,4.5], [4.2, 5, 6,3.6,4.3],[2,3,4,3.4,5.6],[0.2,3.4,4.5,6,4]])
       
print(theta[:,1])
circle(theta)
Jules
  • 35
  • 1
  • 7

1 Answers1

2

Looks like you were very close. Instead of plotting just the x,y coordinates of the points on the circle you can plot the lines with plt.plot([x1, x2], [y1, y2]) where x1 and y1 are 0

I've just iterated through the points in the first row of your array and done that.

for i in range(len(theta[0])):
    plt.plot([0, radius*np.cos(theta[0][i])], [0, radius*np.sin(theta[0][i])])

Image here