Ugly hack to flush plots to the screen as they are updated.
[pypiezo.git] / pypiezo / afm.py
index 106885dc425b0cac5eb469d0e6d39df765fbadd2..da631b0f827fc1497fd61c682e2cfe56d566849a 100644 (file)
@@ -379,6 +379,8 @@ class AFMPiezo (_base.Piezo):
         if plot:
             if not _matplotlib:
                 raise _matplotlib_import_error
+            interactive = _matplotlib.is_interactive()
+            _matplotlib.interactive(True)
             figure = _matplotlib_pyplot.figure()
             axes = figure.add_subplot(1, 1, 1)
             axes.hold(False)
@@ -386,6 +388,8 @@ class AFMPiezo (_base.Piezo):
             axes.set_title('wiggle for interference %s' % timestamp)
             plot_p = axes.plot(out, out, 'b.-')
             figure.show()
+            _matplotlib_pyplot.draw()
+            _matplotlib_pyplot.show()
         cycle = 0
         c = _CheckForKeypress(test_mode=keypress_test_mode)
         while c.input() == None:
@@ -407,8 +411,10 @@ class AFMPiezo (_base.Piezo):
             if plot:
                 plot_p[0].set_ydata(data[:,0])
                 axes.set_ylim([data.min(), data.max()])
-                #_flush_plot()
+                _matplotlib_pyplot.draw()
             cycle += 1
+        if plot:
+            _matplotlib.interactive(interactive)
         self.last_output[config['axis']] = out[-1,0]
         _LOG.debug('interference wiggle complete')