dum*_*umm 1 geometry numpy matplotlib
我想使用numpy和matplotlib绘制一个单位圆(cos + sin)。我写了以下内容:
t = np.linspace(0,np.pi*2,100)
circ = np.concatenate((np.cos(t),np.sin(t)))
Run Code Online (Sandbox Code Playgroud)
我策划了,但是失败了。
ax.plot(t,circ,linewidth=1)
ValueError: x and y must have same first dimension
Run Code Online (Sandbox Code Playgroud)
plot不做参数图。您必须给它x和y值,而不是t。
x是cos(t)和y是sin(t),因此将这些数组赋给plot:
ax.plot(np.cos(t), np.sin(t), linewidth=1)
Run Code Online (Sandbox Code Playgroud)
或者您可以使用 Circle (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()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5354 次 |
| 最近记录: |