I have implemented a prototype of interactive backend detection. As I
proposed earlier, I added an extra rc parameter 'backend_fallback' that
allows pyplot to inspect sys.modules on load and try to redirect
interactive backends to the appropriate ones.
I am attaching a patch, not for inclusion, as I still want to check
different details on interactivity, and the behavior of the show command,
but for comments and triage. I have tested it in various apps, and I
think it is interesting to review the different mainstream apps
presenting a interactive shell in which pylab can be used interactively.
* wx apps. In mayavi2, my near-born ipython frontend the attached patch
works seamlessly, with or without the interactive switch. In SPE
(wx-based IDE) it does not work, and I suspect this is because of ugly
things SPE does to the wx image-loading, for theming reasons, as I see
totally unrelated errors.
* Qt: In Eric4 the qt detection does not work as it seems that Eric
spawns a new python process. As a result, as long as you keep the
interactive switch off, pylab works great, but you really have to use a
blocking show. Does anybody now a Qt program that has an interactive
* In IDLE I can't figure out what is happening. I must confess that I do not
know much about Tkinter, and I am not too sure how matplotlib is
supposed to collaborate with an existing Tk mainloop.
* The only GTK program I could think of with an interactive python prompt
was accerciser, an pylab now works out of the box there, in interactive
mode or not.
Of course in ipython -q|q4|w|g-thread, my addition work seamlessly, but
that was too easy :).
Some remarks that came out of this extensive testing:
- show starts a mainloop and is blocking even if there are not windows
open. This basically leads to a deadlock where the user cannot
interrupt the mainloop. This can probably be easily fixed, and I'll
look into it.
- we cannot guess whether the user want to be in interactive mode or
not: there is a potential large cost of being in interactive mode due to
continuous refreshing of the UI. Ipython gets it right by turning the
interactive mode off when running a script, but when need the host
environment to make this decision and we cannot make it in matplotlib.
However, I believe it is important to expose more this
functionality, as the user will now probably have to make this
decision. This is why I have add the import of "interactive" in
- this brings up the fact that the user experience can be increased a
lot if the host environment collaborates with matplotlib. This is why
we discussed with John the idea of adding a "vendor registry", a
light-weight module that an environment could import at little cost
to tell matplotlib what backend to use, whether to put the
interactive switch, and hopefully more, like maybe a factory to
create new figure, as this would allow embedding these figures in an IDE.
We do this with mayavi2, where the figures created by mlab are
standalone windows when the fullblown environment is not running, but
integrated windows when it is running.
I am sure there is more that we can learn. Please come up with ideas so
that we can see better what is the way forward for integrating matplotlib
to graphical shells and environments.
backend_detect.patch (701 Bytes)