如何提高pyqtgraph中大量文本项的绘制速度

2024-10-01 09:28:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在pyqtgraph中标记一些位置

这是代码

   def set_history_arrow(self):
        print(f"===> up: {len(self.up)} down: {len(self.down)}")
        for up in self.up:
            print("up", self.up.index(up))
            up_arrow = pg.TextItem('↑', fill=(255, 0, 0))
            self.plot_widget.addItem(up_arrow)
            up_arrow.setPos(up, self.data[up])
        for down in self.down:
            print("down", self.down.index(down))
            down_arrow = pg.TextItem("↓", fill=(0, 238, 118))
            self.plot_widget.addItem(down_arrow)
            down_arrow.setPos(down, self.data[down])
    

数据总和为:41363

他们的数量

===> up: 4259 down: 2559

它执行起来很慢

我怎样才能提高速度


Tags: inselfforindexlenplotwidgetfill
2条回答

如果您有大量文本,那么使用QPainter.drawTexthttp://doc.qt.io/qt-5/qpainter.html#drawText更直接地呈现文本可能会使您受益匪浅

PyQtGraph中有一个在此处绘制自定义图形的示例:https://github.com/pyqtgraph/pyqtgraph/blob/master/examples/customGraphicsItem.py

该示例没有显示如何绘制文本,这本身也不是一件小事

这要复杂得多,@somewheve的建议可能更容易实施

只要使用ScatterPlotItem就行了

相关问题 更多 >