4

I'm trying to make a PlotWidget moving (from left to right) really fast like if it was an electrocariogram. Here's an example of what i want (except that he used PyQwt (which is incompatible with my projet because I use PySide (and not PyQt) and also except that I want the X axis to move from left to right too) :

enter image description here

However, I have no idea how to do it. I can plot the grab, i can make it move from left to right using the method :

 myPlotWidget.setXRange(0, 100)

then

  myPlotWidget.setXRange(1, 101)

Which made it looks like it moved from left to right (of 1 unit) but I don't now how to make it smooth and automatic. I tried to make a loop which looks like this :

 for i in range(1000):
     myPlotWidget.setXRange(10+i, 100+i, update=True)

But during the loop the plot is not updated... The plot is only updated when the loop is over, so I cannot see it "moving" from left to right, I just have the final result.

Someone can help me on this? Is there any way I can force the redraw the 1000 times of the loop?

I was first thinking it was computing too fast so I tried this

 for i in range(1000):
     myPlotWidget.setXRange(10+i, 100+i, update=True)
     time.sleep

but of course it didn't work.

Thank you so much for your help !

user3369214
  • 421
  • 1
  • 9
  • 21
  • 1
    See: http://stackoverflow.com/questions/18080170/what-is-the-easiest-way-to-achieve-realtime-plotting-in-pyqtgraph – Luke Apr 02 '14 at 04:01

1 Answers1

-1

At the end of the loop, when it is updated, you have something like myPlotWidget.update(), or myPlotWidget.canvas.draw(), right?

Just move that into the for loop. This will get slow if you are trying to plot a large amount of data though.

will
  • 10,260
  • 6
  • 46
  • 69
  • 6
    No; QWidget.update() only _schedules_ a repaint for later. You must call QApplication.processEvents() or return to the Qt event loop. – Luke Apr 02 '14 at 04:02
  • Luke is right, thank you so much for your help. It works perfectly with QApplication.processEvents(). Can you post it as an answer (not a comment) of the question for possible future people having the same question. I ll be glad to check it as an "usefull answer" :) Thank you again – user3369214 Apr 02 '14 at 12:47