【问题标题】:pyqtgraph rotate ScatterplotItems as spotspyqtgraph 将 ScatterplotItems 旋转为点
【发布时间】:2018-08-29 01:51:22
【问题描述】:

在 pyqtgraph 中,您可以为每个项目本身或一大堆散点图(使用点)散点图。处理大型数据集我更喜欢最后一种方法,因为数字很轻并且可以移动而不会在整个屏幕上滞后。

我的问题

我的一些符号需要一个角度...这不是什么大问题,但是如果我将它们单独添加到绘图中,它会导致一个滞后的数字。所以我的问题是我目前无法找到一种合适的方法来对整个事物进行子类化并为关键字参数“旋转”/“角度”实现一个小方法。有没有人已经完成了这个任务或者有什么想法?

非常感谢您!

【问题讨论】:

    标签: python pyqtgraph


    【解决方案1】:

    今天又看了一遍,我终于发现它太简单了:在将符号添加到 ScatterPlotItem 之前旋转我的符号就可以了。为了文档和其他一些苦苦挣扎的程序员,sn-p:

    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)
    

    【讨论】:

      猜你喜欢
      • 2019-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-19
      • 2011-11-28
      • 2016-09-26
      • 1970-01-01
      • 2010-12-06
      相关资源
      最近更新 更多