From: Roberto Rodríguez-R. <ro...@gm...> - 2012-02-20 16:19:50
|
Hi, I need to do a bar graph with categories, I found these example http://www.ibm.com/developerworks/aix/library/au-gnuplot/index.html I need to do something similar, for many data. I tried to replicate the example on python. I wrote the respective code I append it at the end of the message. but I got these error: File "./graph.py", line 119 g.plot(data using 2:xtic(1) title "Oct-09 data growth(gb)", '' using 3 title "Nov-09 data growth(gb)", '' using 4 title "Dec-09 data growth(gb)") ^ SyntaxError: invalid syntax The function fileopen2 is just for parsing the file with the data, I got a matrix wich I tried to graph. The problem is with the plot command, I don't know how to manage categories with gnuplot.py, I have looking in the web in several places but all the examples don't touch these part. these is my code #! /usr/bin/env python import Gnuplot, Gnuplot.funcutils, sys import sys import re import math #******************************************************************************* def plot2D(data): print sys.maxint g = Gnuplot.Gnuplot() #persist=1) g.title('Memory writes') g('set terminal png truecolor') g('set grid') g('set style data histograms') # give gnuplot an arbitrary command g('set style fill solid 1.00 border -1') g('set xlabel "page_number"') g('set ylabel "number of writes"') g('set autoscale') g.plot(data using 2:xtic(1) title "Oct-09 data growth(gb)", '' using 3 title "Nov-09 data growth(gb)", '' using 4 title "Dec-09 data growth(gb)") g.hardcopy("blah.png",terminal="png") raw_input('Press enter to continue...\n') #******************************************************************************* #******************************************************************************* def file_open2(DataFile): #Open the file # print "open" try: data_file = open(DataFile, "r") #open the file data_points=data_file.read() #save the file in a list line_points=data_points.split('\n') #split the file by new lines data_file.close() except IOError, e: print >> sys.stderr, "File Open Error:", e sys.exit(2) reg_exp=re.compile(r"\s+") #reg_exp for separate each token in the list mem=[[]] print "Putting data in an array" for i in range(len(line_points)-1): mem_line=reg_exp.split(line_points[i]) for j in range(len(mem_line)): if j==0: mem[i].append((mem_line[j])) else: mem[i].append(float(mem_line[j])) mem.append([]) mem.pop() return mem #******************************************************************************* if __name__ == '__main__': plot2D(file_open2(sys.argv[1])) the file that have the data contains: hdisk2 420 425 410 hdisk3 700 780 760 hdisk4 450 450 452 hdisk5 680 702 690 hdisk6 320 330 329 hdisk7 530 515 514 I really appreciate any help. Thank you -- Best Regards Roberto |