[SciPy-user] Alternative to NumTut's view() function?

Fernando Perez scipy-user@scipy.net
Fri, 14 Feb 2003 19:32:59 -0700 (MST)


  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.
  Send mail to mime@docserver.cac.washington.edu for more info.

---1971297403-43117864-1045276379=:8767
Content-Type: TEXT/PLAIN; charset=US-ASCII

On Thu, 13 Feb 2003, David Ascher wrote:

> >Any suggestions?
> >  
> >
> It's working ok for me on win2k. I'll try tomorrow on rh8 at work.  
> 
> In the meantime, try forcing _inidle to be true before view() is 
> defined.  See if that behavior works better for you.

Well, that does help quite a bit.  However, the keyboard response is still a
bit sluggish, which I honestly can't stand.  I type reasonably fast and I 
can't stand a delay in typing at a console (it is however far better than 
before, and perhaps quite usable for most).

However, I've modified view.py and now have a reasonably functional version. 
I'm attaching it to this message for the benefit of  others, since it seems 
that this problem is reasonably common. I also modified view() to accept a 
single scaling factor besides the tuple of (scalex,scaley).  This allows 
zooming in both directions with a single number, a  common operation.

Thanks a lot for all the suggestions, I did look at the tutorial and various 
other options.  I did go ahead, against my better judgement, and installed 
wxpython.  I say this because in the past, getting wxpython to work has been a 
frustrating experience every single time.

No change :)  I tried reproducing the instructions from teh tutorial mentioned 
in another reply, and I got only a dead window labelled 'Figure 0'.  The 
window showed no contents and none of its control widgets worked (including 
'close').  I could only kill it by exiting the python shell. Here's my text 
output:

[libfmwt]> python
Python 2.2.1 (#1, Aug 30 2002, 12:15:30)
[GCC 3.2 20020822 (Red Hat Linux Rawhide 3.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gui_thread
>>> from scipy import plt
>>> from scipy import *
>>> img = plt.lena()
>>> plt.image(img)
<type 'array'> ['__copy__', '__deepcopy__', 'astype', 'byteswapped', 'copy', 
'iscontiguous', 'itemsize', 'resize', 'savespace', 'spacesaver', 'tolist', 
'toscalar', 'tostring', 'typecode']
<C wxFrame instance at _86445e0_wxFrame_p>
>>>

Note that after the gui_thread statement, I did NOT see <wxPython imported> 
printed as the tutorial says should occur.  

This was done with a cvs copy of scipy from today which passed all tests with 
scipy.test(level=10), on a RedHat 8.0 machine. 

I'm sure that eventually it will be very nice to use all the nice 
scipy-provided plotting functionality.  But until that day arrives, the 
simple-minded view.py I attach here may be of use to some.  

Thanks again to all those who replied in various forms (in case I don't reply
to you directly, I did read all the responses).

Best regards,

Fernando.

---1971297403-43117864-1045276379=:8767
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="view.py"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.LNX.4.44.0302141932590.8767@datamat.colorado.edu>
Content-Description: 
Content-Disposition: attachment; filename="view.py"

IiIiDQpEaXNwbGF5aW5nIGltYWdlIGZpbGVzIGluIGEgc2VwYXJhdGUgdGhy
ZWFkIG9uIFRrK3RocmVhZCwgdy8geHYgaW4NCmZvcmtlZCAmIGV4ZWN2J2Vk
IHByb2Nlc3NlcyBvdGhlcndpc2UuDQoNCnZpZXcoYXJyYXkpOiAgd2lsbCBz
cGF3biBhIGRpc3BsYXlpbmcgcHJvZ3JhbSBmb3IgYXJyYXlzIHdoaWNoIGFy
ZQ0KICAgICAgICAgICAgICBlaXRoZXIgTnhNIG9yIE54TXgzLiAgZG9lcyB0
aGUgJ21pbi9tYXgnIGFuZCBjb252ZXJzaW9uDQogICAgICAgICAgICAgIHRv
IGNoYXIuDQoNCmFycmF5MnBwbShhcnJheSk6IGdpdmVuIGFuIE54TSBvciBO
eE14MyBhcnJheSwgcmV0dXJucyBhIHBwbSBzdHJpbmcNCiAgICAgICAgICAg
ICAgICAgIHdoaWNoIGlzIGEgdmFsaWQgdGhpbmcgdG8gcHV0IGluIGEgUFBN
IGZpbGUuICAob3INCiAgICAgICAgICAgICAgICAgIFBHTSBmaWxlIGlmIE54
TSBmaWxlKS4NCg0KVE9ETzoNCiAgLSBhdXRvbWF0aWMgc2NhbGluZyBmb3Ig
c21hbGwgaW1hZ2VzDQogIC0gYWNjZXB0IHJhbmstMSBhcnJheXMNCg0KT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