Standardize matplotlib rendering on figure.canvas.draw() and figure.show().
authorW. Trevor King <wking@tremily.us>
Thu, 7 Feb 2013 06:01:25 +0000 (01:01 -0500)
committerW. Trevor King <wking@tremily.us>
Thu, 7 Feb 2013 06:01:25 +0000 (01:01 -0500)
In interactive mode, skip the no-op pyplot.show().  In non-interactive
mode, the show() calls will block until the window is closed.

unfold_protein/unfolder.py

index 5a827169850f51c4fdc1118d9b331351a53d917b..57def437eed744150ae91e4b380bfb5ebb95c207 100755 (executable)
@@ -33,6 +33,7 @@ from . import package_config as _package_config
 
 try:
     import numpy as _numpy
 
 try:
     import numpy as _numpy
+    import matplotlib as _matplotlib
     from matplotlib import pyplot as _pyplot
     _pyplot.ion()
     FIGURE = _pyplot.figure()
     from matplotlib import pyplot as _pyplot
     _pyplot.ion()
     FIGURE = _pyplot.figure()
@@ -118,7 +119,11 @@ class Unfolder (object):
                 axes = FIGURE.add_subplot(1, 1, 1)
                 axes.plot(data['z'], data['deflection'], label='Approach')
                 axes.set_title('Unfolding too far')
                 axes = FIGURE.add_subplot(1, 1, 1)
                 axes.plot(data['z'], data['deflection'], label='Approach')
                 axes.set_title('Unfolding too far')
-                _pyplot.show()
+                FIGURE.canvas.draw()
+                if hasattr(FIGURE, 'show'):
+                    FIGURE.show()
+                if not _matplotlib.is_interactive():
+                    _pyplot.show()
             _LOG.debug('raising ExceptionTooFar')
             raise ExceptionTooFar
         return data
             _LOG.debug('raising ExceptionTooFar')
             raise ExceptionTooFar
         return data
@@ -233,8 +238,11 @@ class Unfolder (object):
         axes.plot(unfold['z'], unfold['deflection'], label='Unfold')
         axes.legend(loc='best')
         axes.set_title('Unfolding')
         axes.plot(unfold['z'], unfold['deflection'], label='Unfold')
         axes.legend(loc='best')
         axes.set_title('Unfolding')
-        _pyplot.draw()
-        _pyplot.show()
+        FIGURE.canvas.draw()
+        if hasattr(FIGURE, 'show'):
+            FIGURE.show()
+        if not _matplotlib.is_interactive():
+            _pyplot.show()
 
     def zero_piezo(self):
         _LOG.info('zero piezo')
 
     def zero_piezo(self):
         _LOG.info('zero piezo')