Matplotlib中的多项式函数显示多行
我正在遇到这个问题中提出的同一问题:也是如此多项式图上的许多线条和曲线
该问题的解决方案似乎是根据X轴对点进行排序。在我的情况下,我很确定我的数据已经分类了,因为我将X数组放入图中:
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 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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的示例确实确实在X轴上具有未分类的数据,而解决方案就像您链接的问题一样:
Your example does indeed have unsorted data in the x axis, and the solution is just as in the question you linked: