Guest User

Untitled

a guest
Aug 10th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. import numpy as np
  2. import pyqtgraph as pg
  3.  
  4. # define a symbol bowtie style
  5. _mos = np.asarray([
  6. [0.5, 0.25],
  7. [0.5, -0.25],
  8. [-0.5, 0.25],
  9. [-0.5, -0.25],
  10. [0.5, 0.25]
  11. ])
  12. my_symbol = pg.arrayToQPath(_mos[:, 0], _mos[:, 1], connect='all')
  13.  
  14. # define color and stuff for your items
  15. exit_item = pg.ScatterPlotItem(
  16. size=20,
  17. pen=pg.mkPen(128, 128, 128, 255),
  18. brush=pg.mkBrush(255, 255, 255, 255),
  19. )
  20.  
  21. # calculate angle between two sets of points
  22. angle = np.arctan2(np.asarray(y1-y0), np.asarray(x1-x0)) * 180/np.pi
  23.  
  24. # rotate symbol with that angle
  25. tr = QTransform()
  26. angle_rot = tr.rotate(angle)
  27. my_rotated_symbol = angle_rot.map(my_symbol)
  28.  
  29. # may be a whole list of spots with different angles and positions
  30. exit_spots = []
  31. exit_spots.append({
  32. 'pos': (0, 0),
  33. 'symbol': my_rotated_symbol
  34. })
  35.  
  36. # add the spots to the item
  37. exit_item.addPoints(exit_spots)
  38.  
  39. # create a plot and add the content
  40. win = pg.GraphicsWindow()
  41. plot = win.addPlot()
  42. plot.addItem(exit_item)
Add Comment
Please, Sign In to add comment