Eric Firing wrote:
> Robert Cimrman wrote:
>> Eric Firing wrote:
>>> Robert and any other spy users:
>>> I have committed to svn a new axes method, spy3, that combines a
>>> modification of the functionality of both spy and spy2. I hope you
>>> can check it out. If it looks OK, then I would like to simply
>>> replace spy and spy2 with this combined version. In that case the
>>> pylab interface, which now gives access to spy and spy2, would have a
>>> single spy function which would access the new version. My suspicion
>>> is that spy is used almost entirely in interactive mode, and probably
>>> not by very many people, so that this changeover can be made quickly
>>> with little disruption to present users.
>>> Attached is a script illustrating the difference in the way spy3
>>> displays a matrix (it matches the way it is printed: first index is
>>> row number, second is column number, row number increases down)
>>> versus what spy and spy2 do (first index is X, second index is Y).
>>> Also attached is the diff for spy3.
>>> Users may want to comment in particular on the default for the
>>> "aspect" kwarg. Presently it is set to "equal" so that the shape of
>>> the plot is the shape of the array with square cells. This differs
>>> from spy and spy2. The rationale is that it gives the best picture
>>> of what the array looks like, including its shape.
>> Thumbs up :), just add the sparse-full matrix switch to the imshow
>> branch too, if possible. But I am happy with it as it is.
> The sparse-full difference only works with the plot mode; for an image
> there is no alternative to providing a value for every pixel, so I don't
> know of any way to optimize it for the case of sparse storage. A
> polygon collection could be used to achieve the same result in this
> case. I'm not sure it is a good idea, though, because there would be an
> advantage of not converting to a regular array only in the case where
> the array is so large that such a conversion would use a big chunk of
> memory, and in that case the polygons probably would be less than
> single-pixel size anyway, so one would be better off using the present
> symbol-plotting mode.
Yeah, I have tried to write it myself before I posted this message but
found that it probably would not work well - nevertheless I asked :).
What could be done, though, is to raise an exception explaining that
sparse matrices and the image mode don't like each other; as it is, the
function spy3 just dies on asarray (should be st. like asarray(
In :import numpy as nm
In :import scipy.sparse as sp
In :a = nm.array( [[0, 1], [0,1], [2,3]] )
In :b = sp.csr_matrix( a )
In :gca().spy3( b )
exceptions.TypeError Traceback (most
recent call last)
/usr/lib/python2.4/site-packages/matplotlib/axes.py in spy3(self, Z,
precision, marker, markersize, aspect, **kwargs)
4378 if marker is None and markersize is None:
-> 4379 Z = asarray(Z)
4380 if precision is None: mask = Z!=0.
4381 else: mask = absolute(Z)>precision
asarray(seq, type, typecode, dtype)
432 if isinstance(seq, _gen.NDArray) and type is None and
typecode is None:
433 return seq
--> 434 return array(seq, type=type, typecode=typecode, copy=0,
436 inputarray = asarray # Obsolete synonym
array(sequence, typecode, copy, savespace, type, shape, dtype)
415 if (hasattr(sequence,'__getitem__')
416 and hasattr(sequence,'__len__')):
--> 417 return fromlist(sequence,type,shape)
419 ##SEQUENCE is a scalar or unhandleable
fromlist(seq, type, shape, check_overflow, typecode, dtype)
246 return arr
--> 248 if not len(seq) and type is None:
249 type = _nt.Long
163 def __len__(self):
164 # return self.getnnz()
--> 165 raise TypeError, "sparse matrix length is ambiguous; use
166 " or shape"
> Anyway, I'm glad it works for you. Thanks for checking.
Thanks for your fast help!