Embed in GTK + dynamic plot

Hi all!
I'd like to embed a mpl graph into a GTK application (and for that
embedding_in_gtk*.py examples are fine) but I would also like to
dynamically update the graph with time.

Consider like if I want to plot some dynamic system information, like
cpu usage, memory occupation, or so. Than I want to gather those info
at 1 sec interval, and dynamically update the graph adding the new
values.

How can I do it? I'm stuck with the "update data as they come" part
(please note I need for GTK embedded mpl code).

Thanks in advance,
Sandro

PS: if there's someone that knows how to gather cpu percentage usage
on a linux sys, please tell me :slight_smile: It seems not that easy to find it
out from google :wink:

···

--
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi

Hi all!
I'd like to embed a mpl graph into a GTK application (and for that
embedding_in_gtk*.py examples are fine) but I would also like to
dynamically update the graph with time.

Consider like if I want to plot some dynamic system information, like
cpu usage, memory occupation, or so. Than I want to gather those info
at 1 sec interval, and dynamically update the graph adding the new
values.

How can I do it? I'm stuck with the "update data as they come" part
(please note I need for GTK embedded mpl code).

The idioms in the examples/animations dir should be directly portable
to an embedded gtk app, eg simple_anim_gtk.py,
dynamic_image_gtkagg.py, etc. You will need to either use an idle
handle, a timeout handler, or a special event in the gtk event
handling framework to trigger an update to the data and draw. You can
extend the gobject signals to handle custom events (eg data arrives)
if you want to go this route, but since you are trying to illustrate
mpl more than gtk (I assume) you may want to go the easy route and use
the timeout or idle handler and just check and see if new data has
arrived and then update as necessary.

PS: if there's someone that knows how to gather cpu percentage usage
on a linux sys, please tell me :slight_smile: It seems not that easy to find it
out from google :wink:

http://tinyurl.com/d7lkga

Sorry :slight_smile: Couldn't resist (less obnoxious answer
http://www.cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.html)

JDH

···

On Sat, May 2, 2009 at 9:42 AM, Sandro Tosi <morph@...10...> wrote:

Hi John,

Hi all!
I'd like to embed a mpl graph into a GTK application (and for that
embedding_in_gtk*.py examples are fine) but I would also like to
dynamically update the graph with time.

Consider like if I want to plot some dynamic system information, like
cpu usage, memory occupation, or so. Than I want to gather those info
at 1 sec interval, and dynamically update the graph adding the new
values.

How can I do it? I'm stuck with the "update data as they come" part
(please note I need for GTK embedded mpl code).

The idioms in the examples/animations dir should be directly portable
to an embedded gtk app, eg simple_anim_gtk.py,
dynamic_image_gtkagg.py, etc. You will need to either use an idle
handle, a timeout handler, or a special event in the gtk event
handling framework to trigger an update to the data and draw. You can
extend the gobject signals to handle custom events (eg data arrives)
if you want to go this route, but since you are trying to illustrate
mpl more than gtk (I assume) you may want to go the easy route and use

you assume right :slight_smile:

the timeout or idle handler and just check and see if new data has
arrived and then update as necessary.

yeah, I solved with "gobject.idle_add"

PS: if there's someone that knows how to gather cpu percentage usage
on a linux sys, please tell me :slight_smile: It seems not that easy to find it
out from google :wink:

http://tinyurl.com/d7lkga

Sorry :slight_smile: Couldn't resist

ehhe :slight_smile: but you're right, I've expressed the question wrongly: I was
searching some python module / binding :slight_smile:

(less obnoxious answer
http://www.cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.html)

At the end I used subprocess module to call sar

Cheers,

···

On Sun, May 3, 2009 at 00:21, John Hunter <jdh2358@...287...> wrote:

On Sat, May 2, 2009 at 9:42 AM, Sandro Tosi <morph@...10...> wrote:

--
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi