spy ignores negative values?

It looks like the 'spy' function ignores negative values

    > (matplotlib 0.87.5).

    > In [30]:spy( ones( (5, 5) ) )[0].get_xdata() Out[30]:
    > array([ 0.5, 0.5, 0.5, 0.5, 0.5, 1.5, 1.5, 1.5, 1.5, 1.5,
    > 2.5, 2.5, 2.5, 2.5, 2.5, 3.5, 3.5, 3.5, 3.5, 3.5, 4.5,
    > 4.5, 4.5, 4.5, 4.5])

    > In [31]:spy( -ones( (5, 5) ) )[0].get_xdata()
    > Out[31]:array(, type=Float)

The implementation of spy is pretty simple:

    def spy(self, Z, marker='s', markersize=10, **kwargs):
        """
        SPY(Z, **kwargs) plots the sparsity pattern of the matrix Z
        using plot markers.

        The line handles are returned

        kwargs control the Line2D properties of the markers:
%(Line2D)s
        """
        if hasattr(Z, 'tocoo'):
            c = Z.tocoo()
            x = c.row
            y = c.col
            z = c.data
        else:
            x,y,z = matplotlib.mlab.get_xyz_where(Z, Z>0)
        return self.plot(x+0.5,y+0.5, linestyle='None',
                         marker=marker,markersize=markersize, **kwargs)

I am not a spy user, though I wrote it. I assume the test should be Z!=0?

Note spy2 (which arguably makes a nicer plot) has the same potential
problem. If there is consensus that it should be !=0 I am happy to
change it.

JDH

John Hunter wrote:
...

I am not a spy user, though I wrote it. I assume the test should be Z!=0?

Note spy2 (which arguably makes a nicer plot) has the same potential
problem. If there is consensus that it should be !=0 I am happy to
change it.

Yes, it should be !=0. The purpose is to show how sparse a matrix is--how much is filled with zeros--by displaying the non-zero entries.

Eric