From: the o. <the...@ho...> - 2010-11-16 22:28:42
|
ok, I know this is not pretty. It's what usually happens when I've been beating my head ineffectively against the wall.issue one: I'm trying to create two lists, one 'read', the other 'write', and then plot them to a png file. I've had success with (much prettier code)using temp files, but it seems that one should not have to use temp files, passing instead an array or file object.issue two: the data points represent (x) - a set of variable intervals (time between responses) and (y) an set of irregular data points (duration of response)the time - xrange - either doesn't format correctly or throws an exception: 'x range is invalid' or the infamous ' Need full using spec for x time data'.code:import os, sys, string, Gnuplot#must be negative, offset from end of filelimit = -100#input file/data mungingwrite_list = []read_list = []input_file_name = sys.argv[1]protocol = sys.argv[2]shortname = input_file_name.rstrip('.db')input_file = open(input_file_name, 'r')input_list = input_file.readlines()input_file.close()for line in input_list[ limit: ]: delta = 0 timestamp = 0.0 line = line.rstrip("\n") line_protocol, line_verb, delta, timestamp = line.split('|') a = [timestamp,delta] if timestamp and delta: if line_protocol == protocol: if line_verb == 'read': read_list.append(a) else: write_list.append(a)#gnuplot stuffgnuplot_file = ""png_file = "plot/_%s.png" % (shortname)g = Gnuplot.Gnuplot()g.title(protocol + ' history for ' + shortname)g('set style data linespoints')g('set xdata time')g('set timefmt "%s"')g('set format x "%b %y"')g('set xtics 2628000')g('set datafile separator ","')g('set autoscale')g('set grid xtics ytics')g('set terminal png')g('set output %s' % (png_file))#cmd = ' "%s" using 1:2 axes x1y1 title "write" with lines, "%s" using 1:2 axes x2y2 title "read" with lines' % (write_list, read_list)write_data = Gnuplot.PlotItems.Data( write_list, using= '1:2 axes x1y1', with_='linespoints', title='write', inline=True)read_data = Gnuplot.PlotItems.Data( read_list, using= '1:2 axes x2y2', with_='linespoints', title='read', inline=True)#allData = [write_data, read_data]#g.plot(cmd)g.plot(write_data) </snip> what am I doing wrong? thanks a lot |