2

I want to draw an unit circle(cos+sin), using numpy and matplotlib. I wrote the following:

t = np.linspace(0,np.pi*2,100)
circ = np.concatenate((np.cos(t),np.sin(t)))

and I plotted, but failed.

ax.plot(t,circ,linewidth=1)
ValueError: x and y must have same first dimension

2 Answers 2

6

plot does not do a parametric plot. You must give it the x and y values, not t.

x is cos(t) and y is sin(t), so give those arrays to plot:

ax.plot(np.cos(t), np.sin(t), linewidth=1)
Sign up to request clarification or add additional context in comments.

Comments

5

Or you can use 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()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.