-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PyQtGraph 0.1.14 takes approximately twice as long to plot colored points in a ScatterPlotItem that 0.1.13 #2960
Comments
I would guess that #2863 is the one affecting you.
Indeed, pyqtgraph/pyqtgraph/graphicsItems/ScatterPlotItem.py Lines 959 to 966 in a4bf606
|
Thanks for the quick reply! I am indeed on a hi-dpi display and that may explain the slow down on my machine. In general, I am supporting users on Windows, Linux and macOS with any number of screens, so I would indeed need to check for the DPI before I plot. I will check that the pull request you mention is indeed the one that affects the rendering performance on my machine and come back to you asap. |
The following script takes < 2.5 secs to run on a particular system with hidpi. import time
import numpy as np
import pyqtgraph as pg
npoints = 200_000
nbrushes = 600
rng = np.random.default_rng(0)
xy = rng.standard_normal(size=(2, npoints))
unique_colors = rng.integers(256, size=(nbrushes, 3))
unique_brushes = [pg.mkBrush(*rgb) for rgb in unique_colors]
random_choice = rng.integers(nbrushes, size=npoints)
random_brushes = [unique_brushes[x] for x in random_choice]
pg.mkQApp()
scatter = pg.ScatterPlotItem(
size=5,
pen=pg.mkPen(None),
brush=pg.mkBrush(255, 255, 255, 128), # To be overridden in the next call depending on a setting
hoverable=True,
hoverSymbol="s",
hoverSize=5,
hoverPen=pg.mkPen("w", width=2),
hoverBrush=None,
)
t0 = time.perf_counter()
# scatter.addPoints(x=xy[0], y=xy[1], brush=random_choice) # SLOW
scatter.addPoints(x=xy[0], y=xy[1], brush=random_brushes) # FAST
t1 = time.perf_counter()
print(f'{t1 - t0:.3f}')
pg.mkQApp()
win = pg.PlotWidget()
win.show()
win.addItem(scatter)
pg.exec() The following should explain why: pyqtgraph/pyqtgraph/graphicsItems/ScatterPlotItem.py Lines 125 to 130 in a4bf606
|
set SLOW version (with dpi mismatch)
FAST version (with dpi mismatch)
FAST version (with dpi matched)
In the FAST version, a matched dpi would have saved only ~340ms. The optimization would be adding one line after the instantiation of self.fragmentAtlas = SymbolAtlas()
self.fragmentAtlas.setDevicePixelRatio(QtGui.QGuiApplication.primaryScreen().devicePixelRatio()) |
Thanks a lot! I will try it out first thing on Monday. |
Hi, when using the suggested fast method (#2960 (comment)) to create just one QBrush per unique identifier and have all other points with the same id reference it, I get the following results: pyQtGraph 0.13.3: 748 +/- 5ms down from ca. 19.6 seconds. Additionally, If I change the device pixel ratio of pyQtGraph 0.13.4: 757 +/- 4ms Apparently, changing the device pixel ratio even (very minimally) slows down the rendering. All in all, reducing the number of QBrush object instantiations more than solves my performance issue with colouring points in the ScatterPlotItem (from 19 down to a quarter of a second), and any additional optimization seem to bring only negligible improvements (or even regressions). |
I had a typo in my instructions (edited):
|
In PyQtGraph version
0.13.4
, coloring points in aScatterPlotItem
withbrush
set to a long index of integers (to rotate over the default number of colors) takes approximately twice as long as in PyQtGraph0.13.3
.Example code:
For
x
,y
, andtid
of about 200,000 elements, andnp.unique(tid)
of approximately 600, on my machine PyQtGrpah0.1.13
takes approximately 10 seconds to plot all colored points, whereas0.1.14
takes approximately 19 seconds.Originally posted by @aarpon in #2719 (comment)
The text was updated successfully, but these errors were encountered: