从原点到圆上的点画一条线
Drawing a line from origin to points on the circle
此代码使用 matplotlib 模块在半径为 2pi 的圆上绘制 NumPy 数组中给定的特定相位行。
如何从原点 (0,0) 到绘制在圆上的这些 points/phases 绘制直线?
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)
看起来你们很亲密。您可以绘制带有 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])])
此代码使用 matplotlib 模块在半径为 2pi 的圆上绘制 NumPy 数组中给定的特定相位行。
如何从原点 (0,0) 到绘制在圆上的这些 points/phases 绘制直线?
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)
看起来你们很亲密。您可以绘制带有 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])])