2017-03-14 16 views
0

我想从列表选择中绘制pyQt4 gui中的多个项目,用户可以选择要显示的图表。他们可以根据需要多次这样做。每次他们绘制新的数据时,即使情节没有,传奇依然存在。我的代码是:pyqtgraph删除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)) 

如何摧毁旧的传说每次运行?

回答

0

我发现这里的解决方案: https://groups.google.com/forum/#!topic/pyqtgraph/DdWyB1ljQdw

我需要添加这个(不知道是否尝试/除非是必要的):

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))