Issue
I am experiencing the same issue that is asked in this question: Too many lines and curves on the polynomial graph
The solution for that issue seems to be sorting the points based on the x axis. In my case im pretty sure my data is already sorted as I am placing my x array into the plot like so:
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
x = np.array([0,0,0,0,0,0,26,0,0,0,0,0,0,0,0,0,214,67,225,250,0,0,0,94,0,0,1366,137])
y = np.array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,5,0,0,0,0,0,0,4,0])
fig3, ax3 = plt.subplots()
ax3.scatter(x, y)
ax3.plot(x, 0 + 0.004*x + 1.63e-06*(x**2), label='squared')
ax3.legend()
plt.show()
I would like to plot just the quadratic line:
Solution
Your example does indeed have unsorted data in the x axis, and the solution is just as in the question you linked:
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
x = np.array([0,0,0,0,0,0,26,0,0,0,0,0,0,0,0,0,214,67,225,250,0,0,0,94,0,0,1366,137])
y = np.array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,5,0,0,0,0,0,0,4,0])
order = np.argsort(x)
fig3, ax3 = plt.subplots()
ax3.scatter(x[order], y[order])
ax3.plot(x[order], 0 + 0.004*x[order] + 1.63e-06*(x[order]**2), label='squared')
ax3.legend()
plt.show()
Answered By - Zorgoth
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.