rotate ScatterplotItems as spots

51 views
Skip to first unread message

Friedrich

unread,
Mar 20, 2018, 5:38:07 AM3/20/18
to pyqtgraph
hi again :-)

in pyqtgraph you can scatterplot each item for itself or a whole bunch of them as bulk (using spots). working with large datasets i prefer the last method since the figure stays light and is movable without lagging all over the screen.

Problem:
some of my symbols i need an angle... that isn't that much of a problem, however if i add them separately to the plot it results in a laggy figure. so my problem is that i am currently unable to find a suitable way to subclass the whole thing and implement a small method for the keyword argument "rotation"/"angle". has anyone finished this task already or has someone an idea?

thank you very much in advance!

Friedrich

unread,
Aug 10, 2018, 10:26:40 AM8/10/18
to pyqtgraph
i found the answer after some rest :-)

import numpy as np
import pyqtgraph as pg

# define a symbol bowtie style
_mos
= np.asarray([
   
[0.5, 0.25],
   
[0.5, -0.25],
   
[-0.5, 0.25],
   
[-0.5, -0.25],
   
[0.5, 0.25]
])
my_symbol
= pg.arrayToQPath(_mos[:, 0], _mos[:, 1], connect='all')

# define color and stuff for your items
exit_item
= pg.ScatterPlotItem(
    size
=20,
    pen
=pg.mkPen(128, 128, 128, 255),
    brush
=pg.mkBrush(255, 255, 255, 255),
)

# calculate angle between two sets of points
angle
= np.arctan2(np.asarray(y1-y0), np.asarray(x1-x0)) * 180/np.pi

# rotate symbol with that angle
tr
= QTransform()
angle_rot
= tr.rotate(angle)
my_rotated_symbol
= angle_rot.map(my_symbol)

# may be a whole list of spots with different angles and positions
exit_spots
= []
exit_spots
.append({
                   
'pos': (0, 0),
                   
'symbol': my_rotated_symbol
               
})

# add the spots to the item
exit_item
.addPoints(exit_spots)

# create a plot and add the content
win
= pg.GraphicsWindow()
plot
= win.addPlot()
plot
.addItem(exit_item)


Reply all
Reply to author
Forward
0 new messages