Using Wing with matplotlib

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

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 appropriate for use with this document: 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.

This document describes how to configure Wing for matplotlib. To get started using Wing as your Python IDE, please refer to the tutorial in Wing's Help menu or read 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)
y = [2, 8, 3, 9, 4]

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.


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 if you cannot resolve problems without disabling Wing's matplotlib support.

Related Documents

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