From 29f0344f89483af840175ba4049ed8e467a3d567 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 2 Aug 2012 12:19:48 -0400 Subject: [PATCH] Only call figure.show if it exits. For example, figures generated with the Agg backend don't have a 'show' method. --- pypiezo/afm.py | 3 ++- pypiezo/base.py | 3 ++- pypiezo/surface.py | 3 ++- pypiezo/wiggle.py | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pypiezo/afm.py b/pypiezo/afm.py index 7e840f6..6e00347 100644 --- a/pypiezo/afm.py +++ b/pypiezo/afm.py @@ -260,7 +260,8 @@ class AFMPiezo (_base.Piezo): axes.plot(pos_array, def_array, '.', label=timestamp) #_pylab.legend(loc='best') figure.canvas.draw() - figure.show() + if hasattr(figure, 'show'): + figure.show() if not _matplotlib.is_interactive(): _matplotlib_pyplot.show() diff --git a/pypiezo/base.py b/pypiezo/base.py index 55ec00b..3220e21 100644 --- a/pypiezo/base.py +++ b/pypiezo/base.py @@ -900,7 +900,8 @@ class Piezo (object): for i,name in enumerate(names): axes.plot(d[:,i], label=name) figure.canvas.draw() - figure.show() + if hasattr(figure, 'show'): + figure.show() if not _matplotlib.is_interactive(): _matplotlib_pyplot.show() return input_data diff --git a/pypiezo/surface.py b/pypiezo/surface.py index fe096bb..6443ea2 100644 --- a/pypiezo/surface.py +++ b/pypiezo/surface.py @@ -236,7 +236,8 @@ def analyze_surface_position_data( fit_fn(final_pos, params)], '-',label='fit') #_pylab.legend(loc='best') figure.canvas.draw() - figure.show() + if hasattr(figure, 'show'): + figure.show() if not _matplotlib.is_interactive(): _matplotlib_pyplot.show() diff --git a/pypiezo/wiggle.py b/pypiezo/wiggle.py index 6067ffa..1f0d705 100644 --- a/pypiezo/wiggle.py +++ b/pypiezo/wiggle.py @@ -138,7 +138,8 @@ def _setup_plot(piezo, config, output): axes.set_title('wiggle for interference %s' % timestamp) plot = axes.plot(output, output, 'b.-') figure.canvas.draw() - figure.show() + if hasattr(figure, 'show'): + figure.show() if not _matplotlib.is_interactive(): _matplotlib_pyplot.show() return (figure, axes, plot) -- 2.26.2