mysql - File input to gnuplot through python -


i trying draw graph of data pull out of mysql database through python gnuplot , gnuplot.py. read latest 10 lines of data mysql database , store them in temp file supposed read gnuplot. can manual way setting through terminal, can't see how should load file gnuplot through python. if can show me easier way this, or way @ all, grateful.

import mysqldb import gnuplot  datafile = open('data', 'w+r')  gp = gnuplot.gnuplot(persist=1) gp('set style data lines') gp('set term png') gp('set output "escan_graph.png"') gp('set datafile separator "|"')  db = mysqldb.connect(host="localhost", user="root", passwd="password", db="zig") cursor = db.cursor()  cursor.execute("select * escan_data")  numrows = int(cursor.rowcount) #get count of total # , display 1 row @ time  if numrows > 10:         start = numrows-10 else:         start = 0  x in range(start,numrows):         row = cursor.fetchone()         print row[0], row[1]         datafile.write(str(row[0]) + "|" + str(row[1]) + "\n")    databuff = gnuplot.data(datafile.read(), title="test")   gp.plot(databuff) 

row[0] x-axis , row[1] y-axis.

this doesn't work because after write file object's cursor @ end of file. if want (you better off not writing data file @ all), need move cursor beginning of file:

datafile.seek(0) 

now can read() beginning of file.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -