1

Pretty much what the title says. I have a QScatterSeries object. I can load data into it and add it to a QChart, but if I try to pull the data back out of it with something like...

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()

I get a AttributeError...

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

points() is definitely a method in QXYSeries, which QScatterSeries extends, so this should be a thing I can do shouldn't it?

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

python 3.6.7

PyQt5 5.11.3

PyQtChart 5.11.3

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
J Webster
  • 239
  • 1
  • 10

2 Answers2

2

There are 2 similar methods:

Which conceptually are 2 containers similar to list so the binding(PyQt5/PySide2) must choose which of them to use, if the docs are reviewed in more detail it is observed that:

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().

It is concluded that the most appropriate is to use pointsVector(), so that is the solution:

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)

Output:

[PyQt5.QtCore.QPointF(1.0, 3.0), PyQt5.QtCore.QPointF(2.0, 5.0), PyQt5.QtCore.QPointF(4.0, 7.0)]
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • QList QXYSeries::points() const is what is missing from QScatterSeries. Looks like pointsVector() will work though. I somehow missed that one – J Webster Jul 07 '19 at 21:47
  • @JWebster Not all methods / classes are mapped by PyQt, many times because it simply can not and others because there is a better option, in this case pointsVector() is more efficient than points() that in the case of Python both generate the same, in the case of C++, they differ in memory management. – eyllanesc Jul 07 '19 at 22:59
0

I met the same problem. My solution is switch to PySide2 from PyQt5, then problem solved.

fgg1991
  • 65
  • 8