python matplotlib 只会绘制整数
我对 python 很陌生。两天。尝试使用 matplotlib 绘制绘图。我收到此错误:
无法使用灵活类型执行reduce
出现错误的行是:
ax.scatter(x,y,z,marker='o')
变量:
ax 定义为:ax = Axes3D(fig)
Fig 定义为:fig = plt.figure()
x, y, z 是列表
有Python专家告诉我为什么吗?我的情节可以工作,但值是整数。首选十进制值。
我读到 python 中的列表不太适合数字...有人可以澄清一下吗?我让它可以处理列表和 ndarray,但所有值都必须是整数。
谢谢!
I'm very new to python. two days. trying to get a plot working with matplotlib. I'm getting this error:
cannot perform reduce with flexible type
the line with the error is:
ax.scatter(x,y,z,marker='o')
Variables:
ax is defined as: ax = Axes3D(fig)
fig is defined as: fig = plt.figure()
x, y, z are lists
Any python experts tell me why? I got the plot to work but the values are integers. Decimal values are preferred.
I read that lists in python are not very good with numbers... can someone clarify? I got it to work with lists and ndarrays but all the values have to be integers.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将您的代码与此基本散点图代码进行比较。请注意,
xs
、ys
、zs
是浮点数的 ndarray。该代码对您有用吗?也许您可以逐步将该代码转变为您自己的代码,以获得有效的代码(或了解您的代码在哪里出现问题)。如果这没有帮助,也许可以发布足够的代码来让我们重现问题。至少,发布的输出
Compare your code with this basic scatter plot code. Notice that there
xs
,ys
,zs
are ndarrays of floats. Does that code work for you? Maybe you can incrementally morph that code into your own to get code that works (or learn where yours breaks).If that doesn't help, perhaps post enough code to allow us to reproduce the problem. At the very least, post the output of
感谢您的回复。
我让它与浮动一起工作,但也许你们都可以告诉我为什么。我刚刚在这里创建了一个帐户,无法编辑我的访客问题...
我正在从 sqlite 数据库获取数据。我可以将 sql 中的值舍入或转换为浮点数,并且它可以工作。我猜测数据是一个数字对象,尽管它是数字的。这是正确的吗?
这是不起作用的代码的摘录。我通过将值转换为浮点数来使其工作。
unutbu 请求 print(repr(x)) 的输出:
最后这是它在 ax.scatter(x,y,z,marker='o') 行上输出的错误:
就像我说的,我认为这只是错误的类型,但是如果你们都可以告诉我是什么类型导致了错误,我可以学到一些东西。
谢谢。
Thanks for the responses.
I got it working with floats but maybe you all can tell me why. I just created an account here and can't edit my guest question...
I'm getting my data from a sqlite database. I can round the values in the sql or cast to floats and it works. I'm guessing that the data was a numerical object even though it was numerical. Is this correct?
Here's an excerpt of the code that doesn't work. I got it to work by casting the values as floats.
unutbu requested the output of print(repr(x)):
and finally here's the error that it outputs on the line ax.scatter(x,y,z,marker='o') :
Like i said i think it was just the wrong type, but if you all can tell me what type causes the error i could learn something.
Thanks.