The matplotlib docs say you need to specify the backend
> before importing matplotlib.matlab. But this seems a bit
> restrictive: what if I want to display a plot on screen,
> and then output the same plot to postscript and print it?
> Normally imports are done only once at the top of a file,
> but I'd like to be able to switch backends anywhere.
The reason you need to specify the backend first is because everything
from making a figure window to mapping an RGB tuple to a color is
backend dependent. The matlab interface wouldn't know what to do with
the 'figure' command without knowing its backend.
What I think would be useful would be able to instantiate any backend
figure with a figure instance from another backend. Eg a backend
factory which did something like
figPS = backend_factory(fig, 'PS')
figGD = backend_factory(fig, 'GD')
Ie, you could initialize a figure in any backend with an instance from
This probably will never work perfectly across all backends, primarily
because the GTK and WX backends both have a mainloop that they enter
and it would be difficult to run both at the same time (though perhaps
possible with GUI thread). But in most cases you wouldn't want too.
But there is no reason you shouldn't be able to create a PS figure or
a GD figure to save. I've been meaning to add a 'PS' extension
checker in the savefig command that would enable you to save to PS
from any backend.
Is this primarily what you need to switch backends for?