SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Richard B. <rg...@gm...> - 2007年03月30日 03:35:32
Hi there
I have a function where I want to display an image, get the user to
zoom in on a region of interest, and then return the axes limits.
But the problem is, I can only use it once, the second time it gets
called in a script the figure doesn't appear. I know this is to do
with show() not being supposed to be used multiple times, but I don't
know what I should be doing instead ... any tips? (I'm still new to
python btw)
Also, if there's a better (more pythonic way) to do what I'm doing, I
would appreciate your input. I'm not sure if what I'm doing with the
region variable is dodgy or not.
Currently, I'm doing this:
from pylab import *
def getroi(im):
 imshow(im)
 title('Zoom in to region of interest, then press a key')
 region = array([0, 0, 0, 0]) # Placeholder values
 def keypressed(event):
 region[:] = [round(i) for i in gca().axis()]
 close(gcf())
 # Connect keypressed to event handler
 connect('key_press_event', keypressed)
 show()
 return region
thanks,
Richard
-- 
Richard Brown
Ph.D. Candidate
Dept. of Mechanical Engineering
University of Canterbury, NZ
From: <bre...@un...> - 2007年03月30日 03:47:22
Not sure what region[:] is supposed to achieve. You are creating a copy 
with the same name, so you are over-riding the original variable.
Hi there
I have a function where I want to display an image, get the user to
zoom in on a region of interest, and then return the axes limits.
But the problem is, I can only use it once, the second time it gets
called in a script the figure doesn't appear. I know this is to do
with show() not being supposed to be used multiple times, but I don't
know what I should be doing instead ... any tips? (I'm still new to
python btw)
Also, if there's a better (more pythonic way) to do what I'm doing, I
would appreciate your input. I'm not sure if what I'm doing with the
region variable is dodgy or not.
Currently, I'm doing this:
from pylab import *
def getroi(im):
 imshow(im)
 title('Zoom in to region of interest, then press a key')
 region = array([0, 0, 0, 0]) # Placeholder values
 def keypressed(event):
 region[:] = [round(i) for i in gca().axis()]
 close(gcf())
 # Connect keypressed to event handler
 connect('key_press_event', keypressed)
 show()
 return region
thanks,
Richard
-- 
Richard Brown
Ph.D. Candidate
Dept. of Mechanical Engineering
University of Canterbury, NZ
-------------------------------------------------------------------------
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
Mat...@li...
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________
UNITED GROUP
This email message is the property of United Group. The information in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. If you are not the intended recipient, you may not disclose, copy or distribute this email, nor take or omit to take any action in reliance on it. United Group accepts no liability for any damage caused by this email or any attachments due to viruses, interference, interception, corruption or unauthorised access.
If you have received this email in error, please notify United Group immediately by email to the sender's email address and delete this document.
From: Richard B. <rg...@gm...> - 2007年03月30日 11:55:26
On 30/03/07, bre...@un...
<bre...@un...> wrote:
>
> Not sure what region[:] is supposed to achieve. You are creating a copy
> with the same name, so you are over-riding the original variable.
>
That doesn't seem to be the case - it returns the right thing on the
first call - i.e. region got changed, but on subsequent calls the
figure is displayed and the function returns array([0,0,0,0]). I
thought taking the slice just gave access to the internals of region
...
How does one assign a new value to a variable in a containing scope?
Richard
>
> Hi there
>
> I have a function where I want to display an image, get the user to
> zoom in on a region of interest, and then return the axes limits.
>
> But the problem is, I can only use it once, the second time it gets
> called in a script the figure doesn't appear. I know this is to do
> with show() not being supposed to be used multiple times, but I don't
> know what I should be doing instead ... any tips? (I'm still new to
> python btw)
>
> Also, if there's a better (more pythonic way) to do what I'm doing, I
> would appreciate your input. I'm not sure if what I'm doing with the
> region variable is dodgy or not.
>
> Currently, I'm doing this:
>
> from pylab import *
>
> def getroi(im):
> imshow(im)
> title('Zoom in to region of interest, then press a key')
> region = array([0, 0, 0, 0]) # Placeholder values
>
> def keypressed(event):
> region[:] = [round(i) for i in gca().axis()]
> close(gcf())
>
> # Connect keypressed to event handler
> connect('key_press_event', keypressed)
>
> show()
> return region
>
>
>
> thanks,
>
> Richard
From: Antonino I. <tri...@gm...> - 2007年04月01日 11:12:15
On 3/30/07, Richard Brown <rg...@gm...> wrote:
> On 30/03/07, bre...@un...
> <bre...@un...> wrote:
> >
> > Not sure what region[:] is supposed to achieve. You are creating a copy
> > with the same name, so you are over-riding the original variable.
> >
>
> That doesn't seem to be the case - it returns the right thing on the
> first call - i.e. region got changed, but on subsequent calls the
> figure is displayed and the function returns array([0,0,0,0]). I
> thought taking the slice just gave access to the internals of region
> ...
>
> How does one assign a new value to a variable in a containing scope?
You can declare the "region" variable as global in keypressed():
def keypressed(event):
 global region
 region = ...
and "region" does not need to get initialized in the containing scope.
Cheers,
 ~ Antonio
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /