【问题标题】:Drawing a line from origin to points on the circle从原点到圆上的点画一条线
【发布时间】:2021-02-20 16:16:26
【问题描述】:

此代码使用 matplotlib 模块在半径为 2pi 的圆上绘制 NumPy 数组中给出的特定相位行。

如何从原点(0,0) 到绘制在圆圈上的这些点/相位绘制直线?


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)

【问题讨论】:

    标签: python numpy matplotlib spyder


    【解决方案1】:

    看起来你很接近。您可以使用plt.plot([x1, x2], [y1, y2]) 绘制线条,而不是仅绘制圆上点的 x,y 坐标,其中 x1 和 y1 为 0

    我刚刚遍历了数组第一行中的点并完成了。

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

    【讨论】:

      猜你喜欢
      • 2018-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多