python - Matplotlib is not recognizing the attribute set_xdata. -
in reference this post: have been attempting run next code plotting , live updating graph. however, welcomed next error every time effort run function: attributeerror: 'list' object has no attribute 'set_xdata'
the rest of function looks following:
def getdata(self): self.data = random.gauss(10,0.1) self.valuetotal.append(self.data) #with value total beingness list instantiated valuetotal = [] self.updatedata() def updatedata(self): if not hasattr(self, 'line'): # should executed on first phone call updatedata self.widget.canvas.ax.clear() self.widget.canvas.ax.hold(true) self.line = self.widget.canvas.ax.plot(self.valuetotal,'r-') self.widget.canvas.ax.grid() else: # modify plotted line self.line.set_xdata(np.arange(len(self.valuetotal))) self.line.set_ydata(self.valuetotal) self.widget.canvas.draw() while code originated sebastian , jake french have not had success implementing this.is there doing wrong? generates error , how can fix?
this used strictly illustration , not copied code. using referential material , felt simplest way communicate problems community. take no credit previous code.
as joe kington pointed out: plot returns list of artists of want first element:
self.line = self.widget.canvas.ax.plot(self.valuetotal,'r-')[0] so, taking first list element, actual line.
a minimal illustration replicate behavior:
l = plt.plot(range(3))[0] l.set_xdata(range(3, 6)) l = plt.plot(range(3)) l.set_xdata(range(3, 6)) the first 1 runs fine , sec 1 gives attributeerror.
python matplotlib pyqt matplotlib-basemap
No comments:
Post a Comment