Discussion:
[pyqtgraph] rotate ScatterplotItems as spots
Friedrich
2018-03-20 09:38:07 UTC
Permalink
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!
--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/59949bfe-066f-4191-a130-011558f8bf91%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Friedrich
2018-08-10 14:26:40 UTC
Permalink
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)
--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/9050d2be-5e0a-4c28-9e68-b5e0498a6925%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...