On Fri, Nov 12, 2010 at 4:20 AM, Olivier Verdier <zelbier@...> wrote:
> I would like to use matplotlib in a programmatic way.
> I thought about creating a Figure object (with no canvas), and plot in
> that Figure.
> Depending on what the user wants, I could then either plot on screen
> or save on file.
> The problem is that I don't know how to connect a Figure object to the
> FigureCanvas that the user chose in its preference file. In other
> words, I would like to do what the function figure() does, but for an
> existing Figure object.
> How could I do that?
If you are using a GUI backend (eg GTKAgg, WXAgg, TkAgg, QtAgg) for
your user interface and call fig.savefig with a hardcopy extension
like PDF, PNG, SVG, EPS or PS, it will do the backend switching for
you. If you'd like to see an example of how to do that for your own
code if you need to, search for switch_backends in FigureCanvasBase: