0

I have this python array: enter image description here

when I use this code:

plt.plot(t, 10 * t)

I get the following line:

enter image description here

But when I use this code:

plt.plot(t, t**2)

I get 2 lines:

enter image description here

What am I doing wrong here, why is it plotting 2 lines instead of 1??

2 Answers 2

2

Your array is not in sorted order. Most values are not displayed in the string representation that you show, but the fact that it is not sorted can be seen from the last two values that are displayed. Exactly what it does contain is unclear - maybe it turns round and backtracks on itself - but if in some place it contains the largest value immediately followed by the smallest value (or values close to these) then this will result in a straight line connecting them, which will be obvious in the quadratic plot, but which in the linear case will not be distinguishable separately from the rest of the plot.

It would be worth plotting simply plt.plot(t) to see what you actually have. Also try

t = numpy.sort(t)
plt.plot(t, t**2)
Sign up to request clarification or add additional context in comments.

Comments

0

I think the figure is simply preserving the first plotted line. Try to add a plt.clf() before plotting the second line. This will clear the figure.

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.