gpt4 book ai didi

python - 属性错误: 'QScatterSeries' object has no attribute 'points'

转载 作者:行者123 更新时间:2023-12-01 00:46:42 26 4
gpt4 key购买 nike

和标题差不多。我有一个 QScatterSeries 对象。我可以将数据加载到其中并将其添加到 QChart,但是如果我尝试使用类似的东西将数据从其中拉出来......

from PyQt5.QtChart import QScatterSeries
from PyQt5.QtCore import QPointF

my_scatter_series.points = QScatterSeries()
my_scatter_series.points.append(QPointF(1.0,3.0))
my_scatter_series.points.append(QPointF(2.0,5.0))
my_scatter_series.points.append(QPointF(4.0,7.0))
point_list = my_scatter_series.points()

我收到属性错误...

AttributeError: 'QScatterSeries' object has no attribute 'points'

points() 绝对是 QXYSeries 中的一个方法,它是 QScatterSeries 的扩展,所以这应该是我可以做的事情,不是吗?

https://doc.qt.io/qt-5/qscatterseries-members.html

Python 3.6.7

PyQt5 5.11.3

PyQtChart 5.11.3

最佳答案

有2种类似的方法:

从概念上讲,这两个容器类似于列表,因此绑定(bind)(PyQt5/PySide2)必须选择使用其中的一个,如果更详细地查看文档,则会发现:

QList QXYSeries::points() const

Returns the points in the series as a list. Use pointsVector() for better performance.

QVector QXYSeries::pointsVector() const

Returns the points in the series as a vector. This is more efficient than calling points().

得出结论,最合适的是使用pointVector(),所以这就是解决方案:

from PyQt5.QtChart import QScatterSeries
from PyQt5.QtCore import QPointF

my_scatter_series = QScatterSeries()
my_scatter_series.append(QPointF(1.0, 3.0))
my_scatter_series.append(QPointF(2.0, 5.0))
my_scatter_series.append(QPointF(4.0, 7.0))
point_list = my_scatter_series.pointsVector()
print(point_list)

输出:

[PyQt5.QtCore.QPointF(1.0, 3.0), PyQt5.QtCore.QPointF(2.0, 5.0), PyQt5.QtCore.QPointF(4.0, 7.0)]

关于python - 属性错误: 'QScatterSeries' object has no attribute 'points' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56925652/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com