From 3afbb2f9d48a8fb665db2413f1ce2f7f2cacff38 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 7 Feb 2013 01:01:25 -0500 Subject: [PATCH] Standardize matplotlib rendering on figure.canvas.draw() and figure.show(). 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 | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/unfold_protein/unfolder.py b/unfold_protein/unfolder.py index 5a82716..57def43 100755 --- a/unfold_protein/unfolder.py +++ b/unfold_protein/unfolder.py @@ -33,6 +33,7 @@ from . import package_config as _package_config try: import numpy as _numpy + import matplotlib as _matplotlib 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') - _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 @@ -233,8 +238,11 @@ class Unfolder (object): 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') -- 2.26.2