Using matplotlib in fltk application: figures not being drawn

I would like to use matplotlib to incorporate plots into my fltk
application. I would like to do this by writing a python function to
create the appropriate graphic using matplotlib. When I want to update
the figure, I want to call an update function written by me in python
which computes the new graphic and displays it. The key point is that I
want to display the figure in a non-blocking way so that control can
return to my fltk application while the figure is still being displayed.

To prototype this I have created a file containing the following python
code

import sys
import fltk
import matplotlib
matplotlib.use('FltkAgg')
import pylab as p
import time

hf=p.figure()
ha=hf.add_subplot(1,1,1)

ha.plot([1,2,3])
p.draw()
time.sleep(5)

The problem I'm having is that if I execute these commands from a python
shell using:
execfile(filename)

(where filename is a file containing the above commands) then the figure
isn't being drawn until after sleep is executed. What I'd like is for
this function to just make the figure and leave it there while control
returns to the calling function. I can then create the plot from my
application(written in c) by linking with python and calling 'execfile'
where execfile contains the commands to make the plot.

I'm new to Python and appreciate any help.

Thanks.
Jeremy

Jeremy Lewi wrote:

I would like to use matplotlib to incorporate plots into my fltk
application.

> The key point is that I

want to display the figure in a non-blocking way so that control can
return to my fltk application while the figure is still being displayed.

To prototype this I have created a file containing the following python
code

import sys
import fltk
import matplotlib
matplotlib.use('FltkAgg')

cool! I didn't know there was an Fltk back-end.

import pylab as p
import time
  
hf=p.figure()

but anyway, this is your issue. With all the GUI back-ends, if you wan to embed the figure in your own app, rather than have pylab create an app for you, you need to create the figure a different way, without pylab. See the various embedded_in _*** examples:

http://matplotlib.sourceforge.net/examples/user_interfaces/index.html

-Chris

ยทยทยท

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...