1

While plotting the sinus of x for x in [0,2*pi] and plotting it using matplotlib, I did this:

x = np.arange(0,2*np.pi,0.1)
y = np.sin(x)
plt.plot(y)
plt.show()

but the result was

sin(x)

where the x-axis does not display the value of x, but the index of x in the array. How can I tell matplotlib.pyplot to give me the actual x-values (0.1, 0.2, ... pi, pi +0.1, .... 2*pi) as one would expect from a function?

2 Answers 2

2

To be fair to matplotlib, you never told it anything about x. Try this:

plt.plot(x, y)
Sign up to request clarification or add additional context in comments.

Comments

0

You should replace y = np.sin(x) for y = [np.sin(i) for i in x]. enter image description here

2 Comments

That would only change the value of y. The actual problem was that I plotted y without giving the x-values as proposed by @Arne
Yeah, I saw that. Thought the mistake was another one

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.