pyplot.figure stealing window focus!!

Hi there,

I am trying to run a python script on my computer at a regular interval [in the background] to output an image file using matplotlib. My problem is that every time the script runs, it momentarily steals focus from whatever I’m working on – which over time gets to be very annoying.

I think that I’ve narrowed it down to a single line in the python script:
fig = plt.figure(facecolor =‘w’, frameon=False)

[note that I’ve imported matplotlib.pyplot as plt earlier]

I made a short video to show the problem:
http://screencast.com/t/MRObeKrx

Can anyone think of a good way to prevent matplotlib from stealing focus?? This is the last problem I have to solve… though I’m out of ideas.

Thanks!
Tyler

Tyler B wrote:

Hi there,

I am trying to run a python script on my computer at a regular
interval [in the background] to output an image file using
matplotlib. My problem is that every time the script runs, it
momentarily steals focus from whatever I'm working on -- which over
time gets to be very annoying.

I think that I've narrowed it down to a single line in the python script:
fig = plt.figure(facecolor ='w', frameon=False)

[note that I've imported matplotlib.pyplot as plt earlier]

I made a short video to show the problem:
http://screencast.com/t/MRObeKrx

Can anyone think of a good way to prevent matplotlib from stealing
focus?? This is the last problem I have to solve.. though I'm out of
ideas.

You don't show the beginning of your script, but try:

import matplotlib
matplotlib.use('Agg')

before any other MPL imports.

I think that did it --- thanks Andrew!!

Just out of curiosity, what does 'Agg' refer to? Also, I'm guessing
that some efficiency is lost once we make Python import the entire
library (as opposed to just pyplot as before) -- is there a more
efficient way, or is that just the price to pay?

Either way, thanks a ton!
Tyler

···

On 4/15/09, Andrew Straw <strawman@...106...> wrote:

Tyler B wrote:

Hi there,

I am trying to run a python script on my computer at a regular
interval [in the background] to output an image file using
matplotlib. My problem is that every time the script runs, it
momentarily steals focus from whatever I'm working on -- which over
time gets to be very annoying.

I think that I've narrowed it down to a single line in the python script:
fig = plt.figure(facecolor ='w', frameon=False)

[note that I've imported matplotlib.pyplot as plt earlier]

I made a short video to show the problem:
http://screencast.com/t/MRObeKrx

Can anyone think of a good way to prevent matplotlib from stealing
focus?? This is the last problem I have to solve.. though I'm out of
ideas.

You don't show the beginning of your script, but try:

import matplotlib
matplotlib.use('Agg')

before any other MPL imports.

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Tyler B wrote:

I think that did it --- thanks Andrew!!

Just out of curiosity, what does 'Agg' refer to?

It's the low-level drawing library, anti-grain. You're bypassing the
loading of whatever other "backend" -- a low-level drawing system --
that matplotlib was loading before.

Also, I'm guessing

that some efficiency is lost once we make Python import the entire
library (as opposed to just pyplot as before) -- is there a more
efficient way, or is that just the price to pay?

Actually, I'd guess it's the opposite -- now you're not loading the
graphical library that was grabbing focus, but merely a low(er) level
drawing library.

-Andrew

Hi List,

now you're not loading the
graphical library that was grabbing focus, but merely a low(er)
level drawing library.

This raises a question I've had for some time. I wish the figure method had x and y kwargs, so that I could specify where the figure window pops up. It always seems to pop up over my console, so that I have to move it to keep typing. It really breaks work flow. I also wish for something like a nofocus kwarg, that will tell the figure window to open in the background, so as not to grab focus. Again, this breaks work flow. This would be more like how Matlab figures behave. Although they popup to the foreground, you can continue typing and focus is correctly applied to the console.

···

--
Christopher Brown, Ph.D.
Department of Speech and Hearing Science
Arizona State University