Matplotlib中的多项式函数显示多行

发布于 2025-01-31 06:53:06 字数 805 浏览 1 评论 0原文

我正在遇到这个问题中提出的同一问题:也是如此多项式图上的许多线条和曲线

该问题的解决方案似乎是根据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()

I would like to plot just the quadratic line:
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

游魂 2025-02-07 06:53:06

您的示例确实确实在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])
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()

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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文