为什么我的 Python 散点图不起作用?

发布于 2024-08-12 05:29:07 字数 415 浏览 7 评论 0原文

我使用 pylab 创建了一个非常简单的散点图。

pylab.scatter(engineSize, fuelMile)
pylab.show()

该程序的其余部分不值得发布,因为正是该行给我带来了问题。当我将“散点”更改为“绘图”时,它会绘制数据图表,但每个点都是一条线的一部分,这使得整个事情变得一团糟。我只想要点,而不是线,但我收到一条巨大的错误消息,其结尾为:

  File "C:\Python26\lib\site-packages\numpy\core\fromnumeric.py", line 1643, in amin
    return amin(axis, out)
TypeError: cannot perform reduce with flexible type

I created a very simple scatter plot using pylab.

pylab.scatter(engineSize, fuelMile)
pylab.show()

The rest of the program isn't worth posting, because it's that line that's giving me the problem. When I change "scatter" to "plot" it graphs the data, but each point is part of a line and that makes the whole things a scribbly mess. I just want points, not a line, but I get this huge error message that ends with:

  File "C:\Python26\lib\site-packages\numpy\core\fromnumeric.py", line 1643, in amin
    return amin(axis, out)
TypeError: cannot perform reduce with flexible type

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

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

发布评论

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

评论(2

末蓝 2024-08-19 05:29:07

我敢打赌,engineSize,fuelMile 是刺痛,尝试打印它们,如果是这种情况,您必须将它们转换为浮点数,然后再将它们作为参数传递给 scatter

floatval = float(strval)

I bet engineSize, fuelMile are stings, try printing them, if that is the case, you have to convert them to float before passing them as arguments to scatter

floatval = float(strval)
好久不见√ 2024-08-19 05:29:07

好的,既然这有效,那么您的输入一定有问题。显然你需要发布更多内容,除非这个“答案”解决了你的问题:

>>> import pylab
>>> pylab.scatter([500, 550, 700, 1100], [5.5, 6.5, 3.1, 9.7])
<matplotlib.collections.RegularPolyCollection object at 0x036F5610>
>>> pylab.show()
(graphing-type stuff ensues)

Okay, so since this works, something must be wrong with your inputs. Clearly you need to post more, unless this "answer" solves your problem:

>>> import pylab
>>> pylab.scatter([500, 550, 700, 1100], [5.5, 6.5, 3.1, 9.7])
<matplotlib.collections.RegularPolyCollection object at 0x036F5610>
>>> pylab.show()
(graphing-type stuff ensues)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文