matplotlib window blocking execution

426 views
Skip to first unread message

alexxx

unread,
Oct 17, 2012, 4:21:32 AM10/17/12
to networkx-discuss

hi everybody,

I am able to display my graph in the matplotlib window, but I'm
currently facing an issue due to the fact that my program's execution
blocks while the window created by plt.show() is open.

I read a lot of advice (e.g.
https://groups.google.com/group/networkx-discuss/browse_thread/thread/aeec78ad8234cf3e/cd27601170a8620a)
concerning the fact that I should use .ion() to enable interactive
mode, but it doesnt work. I wonder (since ipython usage is often
mentioned) if it is related to the fact that I'm developing/running it
as an autonomous program (under Wing IDE).

Anyway, this sequence

plt.ion()
nx.draw(...)
plt.show()

is non-blocking, but the opened window is empty.

Instead, if I dont use plt.ion(), I get the correct graph in the
window, byt my program's main window (in Tkinter, I failed to mention)
stops responding.
Dunno if it does matter, but my program is a Tkinter wiki that opens
the graph window which shows as nodes the pages around the current
page: I'd like to keep it open, and keep on interacting with my main
window, while at the same time be able to use the graph window, since
I connected to it the ability to mouseclick on it and use it as a
hyperlink to navigate to a different page (details here
https://groups.google.com/group/networkx-discuss/browse_thread/thread/aac227e1fb2a4719).

... please oh please dont tell me I have to go on the threading
road...


alessandro




alexxx

unread,
Oct 17, 2012, 8:08:52 AM10/17/12
to networkx-discuss
Steps ahead!
... sorry if it was well known, but apparently you have to use the
tkagg backend if you use matplotlib in Tkinter, and I didnt know it.

So you simply do this:
import matplotlib
matplotlib.use('TkAgg') #http://matplotlib.org/examples/
user_interfaces/embedding_in_tk.html
import pylab
(the order is important I think)

After this, your plt.show() is non-blocking!!!

One big stumbling block I discovered: the Tkagg backend could be not
installed in your system...
I solved it by a) installing tk-devel and b) reinstalling matplotlib
from source (easy_install wont do)


alessandro


On Oct 17, 10:21 am, alexxx <alexxx.ma...@gmail.com> wrote:
> hi everybody,
>
> I am able to display my graph in the matplotlib window, but I'm
> currently facing an issue due to the fact that my program's execution
> blocks while the window created by plt.show() is open.
>
> I read a lot of advice (e.g.https://groups.google.com/group/networkx-discuss/browse_thread/thread...)
> concerning the fact that I should use .ion() to enable interactive
> mode, but it doesnt work. I wonder (since ipython usage is often
> mentioned) if it is related to the fact that I'm developing/running it
> as an autonomous program (under Wing IDE).
>
> Anyway, this sequence
>
>   plt.ion()
>   nx.draw(...)
>   plt.show()
>
> is non-blocking, but the opened window is empty.
>
> Instead, if I dont use plt.ion(), I get the correct graph in the
> window, byt my program's main window (in Tkinter, I failed to mention)
> stops responding.
> Dunno if it does matter, but my program is a Tkinter wiki that opens
> the graph window which shows as nodes the pages around the current
> page: I'd like to keep it open, and keep on interacting with my main
> window, while at the same time be able to use the graph window, since
> I connected to it the ability to mouseclick on it and use it as a
> hyperlink to navigate to a different page (details herehttps://groups.google.com/group/networkx-discuss/browse_thread/thread...).
Reply all
Reply to author
Forward
0 new messages