From: Michael H. <mh...@al...> - 2012-07-30 09:44:26
|
On 07/25/2012 01:06 PM, Vic Watson wrote: > Apologies for my neophyte question, but I’m a bit new to gnuplot, and I > need to get this going this week… > > I have a data set of test results. The format is very simple: > > Attempted,5 > Passed,4 > Failed,1 > Skipped,0 > > I’m trying to put this through gnuplot to get a graph of the results – > specifically, I’m trying to return the image from a mod_python module > running in Apache. > > I’ve got a script that does what I want it to do on the gnuplot command > line :- > > set datafile separator "," > set yrange [0:] > set style fill solid > set terminal gif > set xrange [-.5:3.5] > attempted_row(x,y)=(x eq "Attempted") ? y:1/0 > skipped_row(x,y)=(x eq "Skipped") ? y:1/0 > passed_row(x,y)=(x eq "Passed") ? y:1/0 > failed_row(x,y)=(x eq "Failed") ? y:1/0 > > plot results.txt u ($0):(attempted_row(stringcolumn(1),$2)):xtic(1) w > boxes lc rgb "blue" ti "Attempted", "" u > ($0):(skipped_row(stringcolumn(1),$2)):xtic(1) w boxes lc rgb "yellow" > ti "Skipped", "" u ($0):(passed_row(stringcolumn(1),$2)):xtic(1) w boxes > lc rgb "green" ti "Passed", "" u > ($0):(failed_row(stringcolumn(1),$2)):xtic(1) w boxes lc rgb "red" ti > "Failed > > Now I’m not completely sure how this script works – I cribbed it from a > web page and adjusted it to meet my needs. > > I’m trying to get this running from Gnuplot.py – and it doesn’t. I can > “g.plot(‘results.txt’)”, and I seem to get no response. If I try to put > the data directly into g.plot, I get “ValueError: setting an array > element with a sequence”. The pedestrian way to do this is g = Gnuplot.Gnuplot() g.set(xrange=(-0.5,3.5), yrange=(0,None)) g('set datafile separator ","') g('set style fill solid') ... g.plot( File( 'results.txt', using='($0):(attempted_row(stringcolumn(1),$2)):xtic(1)', with='boxes lc rgb "blue"', title='Attempted', ), File( 'results.txt', using='...', ..., ), ... ) The maintainable way would be to read the datafile and pick it apart into separate lines using Python, then pass each line as a separate Data() object to g.plot(). Michael -- Michael Haggerty mh...@al... http://softwareswirl.blogspot.com/ |