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( 
Z.todense() ))

In [1]:import numpy as nm
In [2]:import scipy.sparse as sp
In [3]:a = nm.array( [[0, 1], [0,1], [2,3]] )
In [4]:b = sp.csr_matrix( a )
In [5]:gca().spy3( b )
---------------------------------------------------------------------------
exceptions.TypeError                                 Traceback (most 
recent call last)

/home/eldaran/<console>

/usr/lib/python2.4/site-packages/matplotlib/axes.py in spy3(self, Z, 
precision, marker, markersize, aspect, **kwargs)
    4377         """
    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

/usr/lib/python2.4/site-packages/numarray/numarraycore.py in 
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, 
dtype=dtype)
     435
     436 inputarray = asarray   # Obsolete synonym

/usr/lib/python2.4/site-packages/numarray/numarraycore.py in 
array(sequence, typecode, copy, savespace, type, shape, dtype)
     415     if (hasattr(sequence,'__getitem__')
     416         and hasattr(sequence,'__len__')):
--> 417         return fromlist(sequence,type,shape)
     418
     419     ##SEQUENCE is a scalar or unhandleable

/usr/lib/python2.4/site-packages/numarray/numarraycore.py in 
fromlist(seq, type, shape, check_overflow, typecode, dtype)
     246         return arr
     247
--> 248     if not len(seq) and type is None:
     249         type = _nt.Long
     250

/home/share/software/usr/lib/python2.4/site-packages/scipy/sparse/sparse.py 
in __len__(self)
     163     def __len__(self):
     164         # return self.getnnz()
--> 165         raise TypeError, "sparse matrix length is ambiguous; use 
getnnz()" \
     166                          " or shape[0]"
     167



> Anyway, I'm glad it works for you.  Thanks for checking.

Thanks for your fast help!
r.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to