2012-04-30 22:20:27 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
2013-02-25 04:09:03 +00:00
|
|
|
"""
|
|
|
|
For testing rapid updates of ScatterPlotItem under various conditions.
|
|
|
|
|
|
|
|
(Scatter plots are still rather slow to draw; expect about 20fps)
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-04-30 22:20:27 +00:00
|
|
|
## Add path to library (just for examples; you do not need this)
|
2012-12-26 22:51:52 +00:00
|
|
|
import initExample
|
2012-04-30 22:20:27 +00:00
|
|
|
|
|
|
|
|
2018-02-17 04:42:34 +00:00
|
|
|
from pyqtgraph.Qt import QtGui, QtCore, QT_LIB
|
2012-04-30 22:20:27 +00:00
|
|
|
import numpy as np
|
|
|
|
import pyqtgraph as pg
|
|
|
|
from pyqtgraph.ptime import time
|
|
|
|
#QtGui.QApplication.setGraphicsSystem('raster')
|
|
|
|
app = QtGui.QApplication([])
|
|
|
|
#mw = QtGui.QMainWindow()
|
|
|
|
#mw.resize(800,800)
|
2021-01-14 03:15:34 +00:00
|
|
|
import importlib
|
|
|
|
ui_template = importlib.import_module(
|
|
|
|
f'ScatterPlotSpeedTestTemplate_{QT_LIB.lower()}')
|
2012-04-30 22:20:27 +00:00
|
|
|
|
2012-05-11 03:37:07 +00:00
|
|
|
win = QtGui.QWidget()
|
2013-02-25 04:09:03 +00:00
|
|
|
win.setWindowTitle('pyqtgraph example: ScatterPlotSpeedTest')
|
2021-01-14 03:15:34 +00:00
|
|
|
ui = ui_template.Ui_Form()
|
2012-05-11 03:37:07 +00:00
|
|
|
ui.setupUi(win)
|
|
|
|
win.show()
|
2012-04-30 22:20:27 +00:00
|
|
|
|
2012-05-11 03:37:07 +00:00
|
|
|
p = ui.plot
|
2014-01-17 01:34:05 +00:00
|
|
|
p.setRange(xRange=[-500, 500], yRange=[-500, 500])
|
2012-04-30 22:20:27 +00:00
|
|
|
|
Scatter Plot Improvements (#1420)
* Added hovering demo to ScatterPlot example
* Use Qt's serialization for SymbolAtlas.symbolMap keys
Yields significant performance improvements when updating the scatter plot's options. See e.g. the plot hover example.
* Further optimized scatter plot picking
* Fix ScatterPlot example tool tip
* Clean up while I'm here
* Compatibility
* Some simple optimizations for ScatterPlotItem
Speedups for ScatterPlotSpeedTest.py:
~50% without pxMode
~ 0% pxMode with useCache
~30% pxMode without useCache
* ~3x speedup in scatter plot speed test with pxMode
* More optimization low-hanging fruit for the scatter plot
* Removed hover example to lazily pass tests
* Avoid segfault
* Re-add hover example to ScatterPlot.py
* Switch to id-based keying for scatter plot symbol atlas
- Use cases exist where serialization-based keying is a significant bottleneck, e.g. updating without atlas invalidation when a large variety pens or brushes are present.
- To avoid a performance hit, the onus is on the user to carefully reuse pen and brush objects.
* Optimized caching in scatter plot hovering example
* Fixed and optimized scatter plot hovering example
* Minor scatter plot optimization
* Cleanup
* Store hovered points in a set for the hovering example
* Keep a limited number symbol atlas entries around for future reuse
* Added a docstring note to remind the user to reuse QPen and QBrush objects for better performance
* Tidied up hovering example
* Typo
* Avoid unnecessary atlas rebuilds
* Refactored SymbolAtlas
* Efficient appending to SymbolAtlas
* SymbolAtlas rewrite
* Cleanup and profiling
* Add randomized brushes to speed test
* Add loc indexer to ScatterPlotItem
* Profile ScatterPlotItem.paint to identify bottlenecks
* Reuse targetRect to improve paint performance
* Readability improvements (opinionated)
* Only need to set x and y of targetRect
- w and h can stay set to 0 (not entirely sure why)
- this is a bit faster than setting all of x, y, w, h
* Minor renaming
* Strip off API changes and leave to another PR
* Renaming
* Compatibility
* Use drawPixmap(x, y, pm, sx, sy, sw, sh) signature to avoid needing to update QRectFs
* Use different drawing approaches for each Qt binding for performance reasons
* Fix a bug introduced two commits ago
Incidentally, I think there is a similar bug in the main branch currently.
* Minor performance and readability improvements
* Strip out source and target QRectF stuff
* Bring source and target QRectF stuff back in a less coupled way
* Leave deprecating getSpotOpts for another PR
* Compatibility fix
* Added docstrings and use SymbolAtlas__len__ where possible
* Fix export issue
* Add missing import
* Add deprecation warnings
* Avoid using deprecated methods
* Fix and cleanup max spot size measurements
* Make creation of style opts entries explicit
* Add hovering API to ScatterPlotItem
* Compatibility
* Marshal pen and brush lists in setPen and setBrush
* Fixed platform dependent bug
2020-12-16 19:07:39 +00:00
|
|
|
count = 500
|
|
|
|
data = np.random.normal(size=(50,count), scale=100)
|
|
|
|
sizeArray = (np.random.random(count) * 20.).astype(int)
|
|
|
|
brushArray = [pg.mkBrush(x) for x in np.random.randint(0, 256, (count, 3))]
|
2012-04-30 22:20:27 +00:00
|
|
|
ptr = 0
|
|
|
|
lastTime = time()
|
|
|
|
fps = None
|
Scatter Plot Improvements (#1420)
* Added hovering demo to ScatterPlot example
* Use Qt's serialization for SymbolAtlas.symbolMap keys
Yields significant performance improvements when updating the scatter plot's options. See e.g. the plot hover example.
* Further optimized scatter plot picking
* Fix ScatterPlot example tool tip
* Clean up while I'm here
* Compatibility
* Some simple optimizations for ScatterPlotItem
Speedups for ScatterPlotSpeedTest.py:
~50% without pxMode
~ 0% pxMode with useCache
~30% pxMode without useCache
* ~3x speedup in scatter plot speed test with pxMode
* More optimization low-hanging fruit for the scatter plot
* Removed hover example to lazily pass tests
* Avoid segfault
* Re-add hover example to ScatterPlot.py
* Switch to id-based keying for scatter plot symbol atlas
- Use cases exist where serialization-based keying is a significant bottleneck, e.g. updating without atlas invalidation when a large variety pens or brushes are present.
- To avoid a performance hit, the onus is on the user to carefully reuse pen and brush objects.
* Optimized caching in scatter plot hovering example
* Fixed and optimized scatter plot hovering example
* Minor scatter plot optimization
* Cleanup
* Store hovered points in a set for the hovering example
* Keep a limited number symbol atlas entries around for future reuse
* Added a docstring note to remind the user to reuse QPen and QBrush objects for better performance
* Tidied up hovering example
* Typo
* Avoid unnecessary atlas rebuilds
* Refactored SymbolAtlas
* Efficient appending to SymbolAtlas
* SymbolAtlas rewrite
* Cleanup and profiling
* Add randomized brushes to speed test
* Add loc indexer to ScatterPlotItem
* Profile ScatterPlotItem.paint to identify bottlenecks
* Reuse targetRect to improve paint performance
* Readability improvements (opinionated)
* Only need to set x and y of targetRect
- w and h can stay set to 0 (not entirely sure why)
- this is a bit faster than setting all of x, y, w, h
* Minor renaming
* Strip off API changes and leave to another PR
* Renaming
* Compatibility
* Use drawPixmap(x, y, pm, sx, sy, sw, sh) signature to avoid needing to update QRectFs
* Use different drawing approaches for each Qt binding for performance reasons
* Fix a bug introduced two commits ago
Incidentally, I think there is a similar bug in the main branch currently.
* Minor performance and readability improvements
* Strip out source and target QRectF stuff
* Bring source and target QRectF stuff back in a less coupled way
* Leave deprecating getSpotOpts for another PR
* Compatibility fix
* Added docstrings and use SymbolAtlas__len__ where possible
* Fix export issue
* Add missing import
* Add deprecation warnings
* Avoid using deprecated methods
* Fix and cleanup max spot size measurements
* Make creation of style opts entries explicit
* Add hovering API to ScatterPlotItem
* Compatibility
* Marshal pen and brush lists in setPen and setBrush
* Fixed platform dependent bug
2020-12-16 19:07:39 +00:00
|
|
|
|
|
|
|
|
2012-04-30 22:20:27 +00:00
|
|
|
def update():
|
|
|
|
global curve, data, ptr, p, lastTime, fps
|
|
|
|
p.clear()
|
2012-10-03 01:23:59 +00:00
|
|
|
if ui.randCheck.isChecked():
|
|
|
|
size = sizeArray
|
Scatter Plot Improvements (#1420)
* Added hovering demo to ScatterPlot example
* Use Qt's serialization for SymbolAtlas.symbolMap keys
Yields significant performance improvements when updating the scatter plot's options. See e.g. the plot hover example.
* Further optimized scatter plot picking
* Fix ScatterPlot example tool tip
* Clean up while I'm here
* Compatibility
* Some simple optimizations for ScatterPlotItem
Speedups for ScatterPlotSpeedTest.py:
~50% without pxMode
~ 0% pxMode with useCache
~30% pxMode without useCache
* ~3x speedup in scatter plot speed test with pxMode
* More optimization low-hanging fruit for the scatter plot
* Removed hover example to lazily pass tests
* Avoid segfault
* Re-add hover example to ScatterPlot.py
* Switch to id-based keying for scatter plot symbol atlas
- Use cases exist where serialization-based keying is a significant bottleneck, e.g. updating without atlas invalidation when a large variety pens or brushes are present.
- To avoid a performance hit, the onus is on the user to carefully reuse pen and brush objects.
* Optimized caching in scatter plot hovering example
* Fixed and optimized scatter plot hovering example
* Minor scatter plot optimization
* Cleanup
* Store hovered points in a set for the hovering example
* Keep a limited number symbol atlas entries around for future reuse
* Added a docstring note to remind the user to reuse QPen and QBrush objects for better performance
* Tidied up hovering example
* Typo
* Avoid unnecessary atlas rebuilds
* Refactored SymbolAtlas
* Efficient appending to SymbolAtlas
* SymbolAtlas rewrite
* Cleanup and profiling
* Add randomized brushes to speed test
* Add loc indexer to ScatterPlotItem
* Profile ScatterPlotItem.paint to identify bottlenecks
* Reuse targetRect to improve paint performance
* Readability improvements (opinionated)
* Only need to set x and y of targetRect
- w and h can stay set to 0 (not entirely sure why)
- this is a bit faster than setting all of x, y, w, h
* Minor renaming
* Strip off API changes and leave to another PR
* Renaming
* Compatibility
* Use drawPixmap(x, y, pm, sx, sy, sw, sh) signature to avoid needing to update QRectFs
* Use different drawing approaches for each Qt binding for performance reasons
* Fix a bug introduced two commits ago
Incidentally, I think there is a similar bug in the main branch currently.
* Minor performance and readability improvements
* Strip out source and target QRectF stuff
* Bring source and target QRectF stuff back in a less coupled way
* Leave deprecating getSpotOpts for another PR
* Compatibility fix
* Added docstrings and use SymbolAtlas__len__ where possible
* Fix export issue
* Add missing import
* Add deprecation warnings
* Avoid using deprecated methods
* Fix and cleanup max spot size measurements
* Make creation of style opts entries explicit
* Add hovering API to ScatterPlotItem
* Compatibility
* Marshal pen and brush lists in setPen and setBrush
* Fixed platform dependent bug
2020-12-16 19:07:39 +00:00
|
|
|
brush = brushArray
|
2012-10-03 01:23:59 +00:00
|
|
|
else:
|
|
|
|
size = ui.sizeSpin.value()
|
Scatter Plot Improvements (#1420)
* Added hovering demo to ScatterPlot example
* Use Qt's serialization for SymbolAtlas.symbolMap keys
Yields significant performance improvements when updating the scatter plot's options. See e.g. the plot hover example.
* Further optimized scatter plot picking
* Fix ScatterPlot example tool tip
* Clean up while I'm here
* Compatibility
* Some simple optimizations for ScatterPlotItem
Speedups for ScatterPlotSpeedTest.py:
~50% without pxMode
~ 0% pxMode with useCache
~30% pxMode without useCache
* ~3x speedup in scatter plot speed test with pxMode
* More optimization low-hanging fruit for the scatter plot
* Removed hover example to lazily pass tests
* Avoid segfault
* Re-add hover example to ScatterPlot.py
* Switch to id-based keying for scatter plot symbol atlas
- Use cases exist where serialization-based keying is a significant bottleneck, e.g. updating without atlas invalidation when a large variety pens or brushes are present.
- To avoid a performance hit, the onus is on the user to carefully reuse pen and brush objects.
* Optimized caching in scatter plot hovering example
* Fixed and optimized scatter plot hovering example
* Minor scatter plot optimization
* Cleanup
* Store hovered points in a set for the hovering example
* Keep a limited number symbol atlas entries around for future reuse
* Added a docstring note to remind the user to reuse QPen and QBrush objects for better performance
* Tidied up hovering example
* Typo
* Avoid unnecessary atlas rebuilds
* Refactored SymbolAtlas
* Efficient appending to SymbolAtlas
* SymbolAtlas rewrite
* Cleanup and profiling
* Add randomized brushes to speed test
* Add loc indexer to ScatterPlotItem
* Profile ScatterPlotItem.paint to identify bottlenecks
* Reuse targetRect to improve paint performance
* Readability improvements (opinionated)
* Only need to set x and y of targetRect
- w and h can stay set to 0 (not entirely sure why)
- this is a bit faster than setting all of x, y, w, h
* Minor renaming
* Strip off API changes and leave to another PR
* Renaming
* Compatibility
* Use drawPixmap(x, y, pm, sx, sy, sw, sh) signature to avoid needing to update QRectFs
* Use different drawing approaches for each Qt binding for performance reasons
* Fix a bug introduced two commits ago
Incidentally, I think there is a similar bug in the main branch currently.
* Minor performance and readability improvements
* Strip out source and target QRectF stuff
* Bring source and target QRectF stuff back in a less coupled way
* Leave deprecating getSpotOpts for another PR
* Compatibility fix
* Added docstrings and use SymbolAtlas__len__ where possible
* Fix export issue
* Add missing import
* Add deprecation warnings
* Avoid using deprecated methods
* Fix and cleanup max spot size measurements
* Make creation of style opts entries explicit
* Add hovering API to ScatterPlotItem
* Compatibility
* Marshal pen and brush lists in setPen and setBrush
* Fixed platform dependent bug
2020-12-16 19:07:39 +00:00
|
|
|
brush = 'b'
|
|
|
|
curve = pg.ScatterPlotItem(x=data[ptr % 50], y=data[(ptr+1) % 50],
|
|
|
|
pen='w', brush=brush, size=size,
|
2014-01-17 01:34:05 +00:00
|
|
|
pxMode=ui.pixelModeCheck.isChecked())
|
2012-04-30 22:20:27 +00:00
|
|
|
p.addItem(curve)
|
|
|
|
ptr += 1
|
|
|
|
now = time()
|
|
|
|
dt = now - lastTime
|
|
|
|
lastTime = now
|
|
|
|
if fps is None:
|
|
|
|
fps = 1.0/dt
|
|
|
|
else:
|
|
|
|
s = np.clip(dt*3., 0, 1)
|
|
|
|
fps = fps * (1-s) + (1.0/dt) * s
|
|
|
|
p.setTitle('%0.2f fps' % fps)
|
2012-10-19 02:48:36 +00:00
|
|
|
p.repaint()
|
|
|
|
#app.processEvents() ## force complete redraw for every plot
|
2012-04-30 22:20:27 +00:00
|
|
|
timer = QtCore.QTimer()
|
|
|
|
timer.timeout.connect(update)
|
|
|
|
timer.start(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Start Qt event loop unless running in interactive mode.
|
2012-12-05 05:25:45 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
|
|
|
|
QtGui.QApplication.instance().exec_()
|