reportervast.blogg.se

Matplotlib scatter marker
Matplotlib scatter marker




matplotlib scatter marker
  1. #Matplotlib scatter marker update
  2. #Matplotlib scatter marker code

It plots current time with a random number in [0, 100) every 200ms infinitely, while also handling auto rescaling of the view: from datetime import datetimeįrom matplotlib.animation import FuncAnimation TL DR: you may want to use matplotlib.animation ( as mentioned in documentation).Īfter digging around various answers and pieces of code, this in fact proved to be a smooth way of drawing incoming data infinitely for me.

#Matplotlib scatter marker update

It is not only slow, but also causes focus to be grabbed upon each update (I had a hard time stopping the plotting python process). The top (and many other) answers were built upon plt.pause(), but that was an old way of animating the plot in matplotlib.

matplotlib scatter marker

You should get a beautiful, smoothly moving graph:

#Matplotlib scatter marker code

Copy-paste this code in a new python-file, and run it. tStyle(QStyleFactory.create('Plastique')) MySrc.data_signal.emit(y) # <- Here you emit a signal! # Believe me, if you don't do this right, things # send data to your GUI in a thread-safe way. # You need to setup a signal slot mechanism, to Self.line1_t_data(np.append(self.n, self.n), np.append(self.y, self.y)) # Extends the _step() method for the TimedAnimation class. TimedAnimation._init_(self, self.fig, interval = 50, blit = True) Self.line1_head = Line2D(,, color='red', marker='o', markeredgecolor='r') Self.line1_tail = Line2D(,, color='red', linewidth=2) Self.n = np.linspace(0, self.xlim - 1, self.xlim) MyDataLoop = threading.Thread(name = 'myDataLoop', target = dataSendLoop, daemon = True, args = (self.addData_callbackFunc,))Ĭlass CustomFigCanvas(FigureCanvas, TimedAnimation): Self.LAYOUT_A.addWidget(self.myFig, *(0,1)) Self.LAYOUT_A.addWidget(self.zoomBtn, *(0,0)) Self.zoomBtn = QtGui.QPushButton(text = 'zoom') X.setMaximumSize(QtCore.QSize(width, height))Ĭlass CustomMainWindow(QtGui.QMainWindow):

matplotlib scatter marker matplotlib scatter marker

X.setMinimumSize(QtCore.QSize(width, height)) tHeightForWidth(x.sizePolicy().hasHeightForWidth()) # EMBED A MATPLOTLIB ANIMATION INSIDE YOUR #įrom matplotlib.animation import TimedAnimationįrom _qt4agg import FigureCanvasQTAgg as FigureCanvas Nevertheless, I've made some code a while ago to plot live graphs, that I would like to share:Ĭode for PyQt4: # I know I'm a bit late to answer this question. Str(doblit), niter / (time.time() - tic)) alpha) * gen.randn(2, n) * sigma + alpha * old_deltaĭisplay the simulation using matplotlib, optionally using blit for speedīackground = _from_bbox(ax.bbox) In particular, using blit to avoid redrawing the background on every frame can give you substantial speed gains (~10x): #!/usr/bin/env pythonĭef randomwalk(dims=(256, 256), n=20, sigma=5, alpha=0.95, seed=1):ĭelta = (1. If you're interested in realtime plotting, I'd recommend looking into matplotlib's animation API.






Matplotlib scatter marker