Jean-Michel> Ok. Now suppose you write an application that runs a
Jean-Michel> set of algorithms not known in advance. These
Jean-Michel> algorithms may or may not create figures depending on
Jean-Michel> what they perform; they may also encounter
Jean-Michel> difficulties (e.g. not enough input data) so that
Jean-Michel> none of them is finally able to create a figure. As
Jean-Michel> this is always better to dissociate code pieces the
Jean-Michel> more as possible, I'd prefer not to use a global
Jean-Michel> variable to trace figure creation. So is there a way
Jean-Michel> to know that no figure was created?
In 0.63, we introduced a flag on the
matplotlib.backends.draw_if_interactive function. If
draw_if_interactive._called is False, the function was never called
and thus no plotting commands were issued. You may be able to use
this to decide whether to call show or not.
Eg , at the end of your script
if draw_if_interactive._called: show()
Note if you are using a pure image backend (eg agg, svg, ps) you do
not need show at all; this is for GUI backends only. Just call
savefig anywhere in your code.
But if you really want full control with no magic globals, I suggest
using the matplotlib API rather than the matlab interface. Here is a
minimal example with the SVG backend to create a figure w/o the matlab
interface
from matplotlib.backends.backend_svg import FigureCanvasSVG
from matplotlib.figure import Figure
fig = Figure()
ax = fig.add_subplot(111)
ax.plot([1,2,3])
canvas = FigureCanvasSVG(fig)
canvas.print_figure('myfile.svg')
There are several examples called embedding_in_*.py at
http://matplotlib.sf.net/examples that show how to do this for your
GUI of choice.
Let me know if you need more help; and be sure to tell which backend
you are targetting.
JDH