Hello,
I wrote a message some weeks ago about a problem I have with pylab,
but I think I probably did not explained it very well.
I am witting a small application that use tkFileDialog to prompt user
to select a file.
Then reads it and plot the data.
I want that the user could be able to press a key and read another
file, to plot it again together with the previous one(s). The problem
is that the thee graph is not drawn until I resize the window. Even
if I use the draw() method.
Any help will be appreciated.
Thanks in advance.
Angel.
code:
import sys
import os
import time
import tkFileDialog
import pylab
pylab.hold(1)
path='E:\\Nima'
n=0
def click(event):
print 'click on: ', event.xdata, event.ydata
def keyp(event):
global path
if event.key.lower()=='o':
fin = tkFileDialog.askopenfilename(initialdir=path)
path=os.path.split(fin)[0]
plot2(fin)
def plot2(fin):
global myplot
global n
f=file(fin, 'r')
lines=f.readlines()
f.close()
X=[]
Y=[]
for line in lines[1:]:
line=line.replace(',', '.')
X.append(float(line.split('\t')[2]))
Y.append(float(line.split('\t')[5]))
l,=myplot.plot(X, Y, label=os.path.split(fin)[1])
myplot.legend()
if n==0:
print "showing..."
n=1
pylab.show()
l.set_visible(1)
myplot.draw()
if __name__=='__main__':
myplot=pylab.subplot(111)
myplot.grid()
kid=pylab.connect('key_press_event', keyp)
pylab.xlabel('Area [A2/molecule]')
pylab.ylabel('SP [mN/m]')
fin = tkFileDialog.askopenfilename(initialdir=path)
path=os.path.split(fin)[0]
plot2(fin)
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users