Using Wing with matplotlib

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

Wing Pro Screenshot

Wing is a Python IDE that can be used to develop, test, and debug Python code written for matplotlib, a powerful plotting library.

Two versions of Wing are appropriate for use with this document: Wing Pro is the full-featured Python IDE for professional developers, 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 by typing the following:

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. To avoid this, 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.

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, GtkCairo, WXAgg (for wxPython 2.5+), Qt5Agg, Qt4Agg, and MacOSX 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 set a breakpoint where you want to stop, and then work in the Debug Console. Type show() in the Debug Console if your plot is not yet visible, or call matplotlib.interactive(True) to put matplotlib into interactive mode so that calling show() is no longer necessary.

Wing adds an item Evaluate Selection in Debug Console to the editor's right-click context menu when the debugger is active.


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

(1) When working in the Debug Console, evaluate the imports that set up matplotlib first, so that Wing can initialize its event loop support before show() is called. Evaluating a whole file at once in the Debug Console (but not the Python Shell) will cause show() to block if matplotlib was not previously imported.

(2) In case there is a problem with the specific matplotlib backend that you are using, try the following as a way to switch to another backend before issuing any other commands:

import matplotlib

Instad of TkAgg you may can also try Qt5Agg (which requires that Qt5 is installed) or WebAgg (which uses a web browser for plot display).

(3) 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 Console.

Please email if you run into problems that you cannot resolve.

Related Documents

For more information see: