

Using Wing IDE with matplotlib

Wing IDE is an integrated development environment that can be used to speed up the process of writing and debugging Python code that is written for matplotlib, a powerful 2D plotting library. Wing provides auto-completion, call tips, a powerful debugger, and many other features that help you write, navigate, and understand Python code.


Note: This document contains only matplotlib specific tips; please refer to the tutorial in the Help menu in Wing and/or the Wing IDE Quickstart Guide.

Working in the Python Shell

Users of matplotlib often work interactively in the Python command line shell. For example, two plots could be shown in succession as follows:

from pylab import plot,show,close
x = range(10)
y = [2, 8, 3, 9, 4]

In some environments, the show() call above will block until the plot window is closed. By default Wing IDE modifies the matplotlib event loop in such a way that the show() call will not block when entered in the integrated Python Shell, and the plot window will be updated continuously as additional commands are typed. In fact show() is not needed at all here since Wing automatically shows and updates plots once plot() is called (but calling it is not a problem, and often will happen if you evaluate code from a source file in the Python Shell). This allows for easier interactive testing of new code and plots.

Code from the editor can be executed in the Python Shell using the Evaluate File in Python Shell item in the Source menu or with the Evaluate Selection in Python Shell item in the editor context menu (right click). By default the Python Shell restarts before evaluating a whole file; this can be disabled in the Python Shell's Options menu.

This special event loop support has been implemented for the TkAgg, GTKAgg, WXAgg (for wxPython 2.5+), Qt4Agg, and MacOS backends. It will not work with other backends.

Working in the Debugger

When executing code that includes show() in the debugger, Wing will block within the show() call just as Python would outside of the debugger if launched on the same file. This is by design, since the debugger seeks to replicate Python run non-interactively.

To work interactively with matplotlib code launched in the debugger, you can set a breakpoint on show() in the code and then work in the Debug Probe. Wing adds an item Evaluate Selection in Debug Probe to the editor context menu (right click) when the debugger is active.


If show() blocks when typed in the Python Shell or Debug Probe, if plots fail to update, or if you run into other event loop problems working with matplotlib you can:

(1) Try the following as a way to switch to another backend before issuing any other commands:

import matplotlib

(2) Try disabling the matplotlib support entirely in Project Properties under the Extensions tab and then restart the Python Shell from its Options menu and restart your debug process, if any. However, this prevents interactive use of matplotlib in the Python Shell and Debug Probe.

Please email support@wingware.com if you cannot resolve problems without disabling Wing's matplotlib support.

Related Documents


Using Wing IDE with matplotlib