My code is:
class Ui_Registos2(object):
def setupUi(self, Registos2, Info):
self.Grafico_2 = pg.PlotWidget(self.centralwidget)
self.Grafico_2.setGeometry(QtCore.QRect(540, 430, 501, 331))
self.Grafico_2.setObjectName("Grafico_2")
def openfile(self):
name = QFileDialog.getOpenFileName()
filename = name[0]
if len(filename) <=0:
return
try:
self.Info.file = open(filename, 'r')
except NameError:
return
self.Info.df = pd.read_excel(filename, sheet_name='Tabela', encoding="utf-8")
i = 0
items = []
# TABLE HEADER
for field in self.Info.df.columns:
items.append(QtGui.QStandardItem(field))
self.model.appendRow(items)
n = [] # CADA LINHA DA TABELA
while i<len(self.Info.df):
linha2 = self.Info.df.loc[i]
n = []
for item in linha2:
print(item)
n.append(QtGui.QStandardItem(str(item)))
self.model.appendRow(n)
i+=1
#FIRST GRAPH
self.y =self.Info.df.loc[:,'%']
self.x =self.Info.df.loc[:,'t']
pen = pg.mkPen(color=(255, 0, 0))
self.data_line = self.Grafico.plot(self.x, self.y, pen=pen)
self.plot = self.pw.plot(x, y, pen=None, symbol="o", symbolBrush="r")
So every time I clicked the button 'openfile', I want to clean the existed data and replot the new one, but PlotWidget rewrite on the existing graph. Is there any way to clean the data?
Thank you.
You can clear a plot with plot.clear(). I cannot test your example but this should work:
self.Grafico.clear()
self.pw.clear()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.