Home » Support » Index of All Documentation » How-Tos » How-Tos for Scientific and Engineering Tools »

Using Wing with matplotlib

Personal+

Wing is a Python IDE that can be used to develop, test, and debug Python code written for matplotlib, a powerful 2D plotting library. Two versions of Wing are available: Wing Pro is the full-featured Python IDE for professional programmers, and Wing Personal is a free alternative with reduced feature set.

If you do not already have Wing installed, download it now.

To get started using Wing, refer to the tutorial in the Help menu in Wing or the 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)
plot(x)
show()
y = [2, 8, 3, 9, 4]
plot(y)
close()

In some environments, the show() call above will block until the plot window is closed. By default Wing 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.

Trouble-shooting

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
matplotlib.use('TkAgg')

(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

Wing provides many other options and tools. For more information:

Using Wing with matplotlib