Bugs and patches posted

Hello -

I just posted a few bugs (and patches to fix them) to the sourceforge bugtracker page before I realized that the email list is preferred.

Short story: I found and (hopefully) fixed a problem with pcolor on non-square arrays, a startup error in the interactive.py shell, and a problem with repeated output when saving postscript backend figures. The details of the bugs and patches are copied below.

Zach Pincus

Here is the relevant information:

···

----------------------------------
pcolor(array) fails when array is not square, on version
0.40i of matplotlib.

Details:
A non-square array causes an indexError on line 1798 of
matplotlib/axes.py:
c = C[i,j]
because iteration has continued past the edge of the array.

This happens because the shape of the X and Y arrays (the
output of a meshgrid call on line 1782) have the wrong
shape. In particular, the shape is backward.
e.g. if C.shape = (x,y), then X.shape = Y.shape = (y, x).

Patch:
Change matplotlib/axes.py line 1782 from:
X, Y = meshgrid(range(numRows), range(numCols))
to:
X, Y = meshgrid(range(numCols), range(numRows))

Rationale:
Meshgrid(range(x), range(y)) returns arrays with
a shape of (y, x), which is a bit counterintuitive.
The documentation(*) bears this out. It is confusing
because the convention therein is that a Nx x Ny entry
array has Nx columns and Ny rows, while a (Nx, Ny)-
shaped array (in Matlab as well as Numeric) has Nx rows
and Ny columns. I don't know why the original meshgrid in
matlab worked this way, but it does.

(*) http://matplotlib.sourceforge.net/matplotlib.mlab.html#-meshgrid

----------------------------------

Problem: examples/interactive.py (version 0.40i) does not
start up properly.

Details: A NameError is raised on startup when the
command on line 206 fails:
interpreter.feed ("ShowOn().set(1)")
This is because ShowOn is not in the global namespace.

Not running ShowOn().set(1) breaks interactive mode
badly.

Patch:
Insert the command:
interpreter.feed("from matplotlib.backends.backend_gtk import ShowOn")
somewhere before line 206.

----------------------------------

Problem:
If savefig() is called more than once on a postscript backend
figure, extra copies of the figure will be appended to the
output.

Details:
Regardless of the file name that the figure is saved under,
each time savefig() is called, an additional copy of the figure
appears at the end of the postscript output. So if savefig() is
called four times, the output from that fourth call will be
four copies of that figure on a multipage postscript file.

Patch:
Insert the following lines at the end of the print_figure
method of the FigurePS class in the file matplotlib/
backends/backend_ps.py (line 189):
self._pswriter = StringIO()
self._pswriter.write(_psHeader)

Rationale:
The postscript backend is not clearing the pswriter
accumulator buffer between repeated calls to print_figure.
So after each call, another copy of the figure gets added to
the buffer and dumped to the output. The patch re-
initializes the pswriter buffer.

Note that the patch is sort of bad form because it duplicates
the pswriter initialization code from the __init__ method of
that class. So if the init method is changed, the patched
lines need to be changed too. Better would be to move the
pswriter initialization to a separate function and call that
from both the init and print_figure methods.