如何使用 numpy 和 matplotlib 绘制单位圆
How to draw an unit circle using numpy and matplotlib
我想用numpy和matplotlib画一个单位圆(cos+sin)。
我写了以下内容:
t = np.linspace(0,np.pi*2,100)
circ = np.concatenate((np.cos(t),np.sin(t)))
我策划了,但失败了。
ax.plot(t,circ,linewidth=1)
ValueError: x and y must have same first dimension
plot
不做参数图。您必须给它 x
和 y
值,而不是 t
.
x
是 cos(t)
而 y
是 sin(t)
,所以将这些数组提供给 plot
:
ax.plot(np.cos(t), np.sin(t), linewidth=1)
或者您可以使用圆形 (http://matplotlib.org/api/patches_api.html):
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
circ = plt.Circle((0, 0), radius=1, edgecolor='b', facecolor='None')
ax.add_patch(circ)
plt.show()
我想用numpy和matplotlib画一个单位圆(cos+sin)。 我写了以下内容:
t = np.linspace(0,np.pi*2,100)
circ = np.concatenate((np.cos(t),np.sin(t)))
我策划了,但失败了。
ax.plot(t,circ,linewidth=1)
ValueError: x and y must have same first dimension
plot
不做参数图。您必须给它 x
和 y
值,而不是 t
.
x
是 cos(t)
而 y
是 sin(t)
,所以将这些数组提供给 plot
:
ax.plot(np.cos(t), np.sin(t), linewidth=1)
或者您可以使用圆形 (http://matplotlib.org/api/patches_api.html):
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
circ = plt.Circle((0, 0), radius=1, edgecolor='b', facecolor='None')
ax.add_patch(circ)
plt.show()