【问题标题】:pyqtgraph delete persisting legend in pyqt4 guipyqtgraph删除pyqt4 gui中的持久图例
【发布时间】:2017-08-05 04:39:44
【问题描述】:

我想从列表选择中在 pyQt4 gui 中绘制多个项目,用户可以选择要显示的绘图。他们可以根据需要多次执行此操作。每次他们绘制新数据时,即使绘图没有,图例也会持续存在。我的代码是:

self.DataPlotter.setLabels(left=("magnitude"),bottom=(str(x_ind)))
title = str(y_ind) + " vs " + str(x_ind)
self.DataPlotter.setTitle(title)
self.DataPlotter.addLegend()

for y,c in zip(y_ind,range(len(y_ind))):
    self.DataPlotter.plot(self.df[x_ind].tolist(),self.df[y].tolist(), name=y, pen=(c,4))

如何在每次运行时销毁旧图例?

【问题讨论】:

    标签: python-2.7 plot pyqt pyqt4 pyqtgraph


    【解决方案1】:

    我在这里找到了解决方案: https://groups.google.com/forum/#!topic/pyqtgraph/DdWyB1ljQdw

    我需要添加这个(不确定是否需要 try/except):

        try:
            self.legend.scene().removeItem(self.legend)
        except Exception as e:
            print e
    

    最终代码如下:

            self.DataPlotter.setLabels(left=("magnitude"),bottom=(str(self.x_ind)))
            title = str(self.y_ind) + " vs " + str(self.x_ind)
            self.DataPlotter.setTitle(title)
            try:
                self.legend.scene().removeItem(self.legend)
            except Exception as e:
                print e
            self.legend = self.DataPlotter.addLegend()
            for y,c in zip(y_ind,range(len(y_ind))):
               self.DataPlotter.plot(self.df[x_ind].tolist(),self.df[y].tolist(), name=y, pen=(c,4))
    

    【讨论】:

      猜你喜欢
      • 2020-07-03
      • 2017-06-08
      • 2017-05-31
      • 2018-01-31
      • 2014-07-07
      • 1970-01-01
      • 2016-10-22
      • 2017-10-18
      • 2023-04-08
      相关资源
      最近更新 更多