Force focus on Figure

Hello,

I have a package that has many functions that bring up plots to show data and interactive plots to interact with data. How can I have my figures show and both be on top and be in focus? The best way I have found to manage Matplotlib plots in my package is to use interactive mode plt.ion() and pause the program with raw_input() statements to show or interact with the plots. This has been working fine with one exception. I have not been able to figure out how have the plot figure come up and have the figure both be on top and in focus. I am using Window XP,Python 2.5.4, Matplotlib version 1.0.0 with backend Tkagg. Tk has a command focus_force(), I have not been able to find a similar command in Matplotlib.

This is a simple example demonstrating the plotting behavior. The second plot is rendered but is not in windows focus.

import matplotlib.pyplot as plt
plt.ion()
fig = plt.figure(figsize=(10,8))
ax = fig.add_axes([.15,.1,.8,.65])
ax.plot([1,2,3])
ax.set_title(‘Fisrt Plot’)
raw_input('Enter to close and Continue: ')
plt.close(fig)
fig2 = plt.figure(figsize=(10,8))
ax = fig2.add_axes([.15,.1,.8,.65])
ax.plot([1,2,3])
ax.set_title(‘Second Plot’)
raw_input('Enter to close and Continue: ')
plt.close(fig2)

Thank you,

Bob Kestner

It looks like I have found a solution. I work for many hours on a problem
before posting so I am surprised I found this only one day after posting my
original question. I went digging in places I am not sure I should and came
with this command that appears to be a solution to my focus problem. It
would be nice to know from an expert if this the recommended method for
forcing focus in Matplotlib.

The command:
fig.canvas.get_tk_widget().focus_force()

My original demo code with the new command showing the focus behavior I
want:

import matplotlib.pyplot as plt
plt.ion()
fig = plt.figure(figsize=(10,8))
ax = fig.add_axes([.15,.1,.8,.65])
ax.plot([1,2,3])
ax.set_title('Fisrt Plot')
fig.canvas.get_tk_widget().focus_force()
raw_input('Enter to close and Continue: ')
#plt.close(fig)
fig2 = plt.figure(figsize=(10,8))
ax = fig2.add_axes([.15,.1,.8,.65])
ax.plot([1,2,3])
ax.set_title('Second Plot')
fig2.canvas.get_tk_widget().focus_force()
raw_input('Enter to close and Continue: ')
#plt.close(fig2)
fig.canvas.get_tk_widget().focus_force()
raw_input('Enter to close and Continue: ')

Bob Kestner

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Force-focus-on-Figure-tp39652p39654.html
Sent from the matplotlib - users mailing list archive at Nabble.com.