From: kevin p. <ke...@ma...> - 2004-11-06 00:20:37
|
i have some data that would like to plot with Gnuplot-py and need to get a little fancier than i am used to. I have data that looks like: 0 5.5 0 1 2 5.5 2 4 4 5.5 4 2 6 5.5 5 3 8 5.5 7 1 10 5.5 9 4 12 5.5 11 3 14 5.5 0 2 16 5.5 2 1 18 5.5 4 4 20 5.5 5 3 The first number is the start time of the event. The second is the duration. The third is the event identifier and the last is what stream it belongs to. I would like to use splot and points of different colors to convey as much info as i can. The X axis would be the time axis (that would take care of the first two parameters) and the Y axis could be the third column. Then for the fouth item, there are only four possibilities (1, 2, 3, or 4), so i thought that i could use points of red, blue, green, black to indicate that. So that is where i am headed... But i have a long way to go and am a gnuplot novice and not a great Python hacker to boot.. Could anyone help me along? I would be grateful for any help. Cheers, kevin Here is some (*gasp*) code. ------------ [snip] ---------------- #! /usr/bin/env python from Numeric import * import Gnuplot, Gnuplot.funcutils def main(): all = [ [ 0, 5.5, 0, 1 ], [ 2, 5.5, 2, 4 ], [ 4, 5.5, 4, 2 ], [ 6, 5.5, 5, 3 ], [ 8, 5.5, 7, 1 ], [ 10, 5.5, 9, 4 ], [ 12, 5.5, 11, 3 ], [ 14, 5.5, 0, 2 ], [ 16, 5.5, 2, 1 ], [ 18, 5.5, 4, 4 ], [ 20, 5.5, 5, 3 ], [ 22, 5.5, 7, 2 ], [ 24, 5.5, 9, 1 ], [ 26, 5.5, 11, 4 ], [ 28, 5.5, 0, 3 ], [ 30, 5.5, 2, 2 ], [ 32, 5.5, 4, 1 ], [ 34, 5.5, 5, 3 ], [ 36, 5.5, 7, 4 ], [ 38, 5.5, 9, 2 ], [ 40, 5.5, 11, 3 ], [ 42, 5.5, 0, 4 ], [ 44, 5.5, 2, 1 ], [ 46, 5.5, 4, 2 ], [ 48, 5.5, 5, 4 ], [ 50, 5.5, 7, 3 ], [ 52, 5.5, 9, 1 ], [ 54, 5.5, 11, 2 ], [ 56, 5.5, 0, 4 ], [ 58, 5.5, 2, 1 ], [ 60, 5.5, 4, 3 ], [ 62, 5.5, 5, 2 ], [ 64, 5.5, 7, 4 ], [ 66, 5.5, 9, 3 ], [ 68, 5.5, 9, 1 ], [ 70, 5.5, 0, 2 ], [ 72, 5.5, 2, 4 ], [ 74, 5.5, 4, 1 ], [ 76, 5.5, 5, 2 ], [ 78, 5.5, 7, 3 ], [ 80, 5.5, 9, 4 ], [ 82, 11.5, 11, 2 ], [ 84, 5.5, 0, 1 ], [ 86, 5.5, 2, 3 ], [ 88, 7.5, 4, 4 ], [ 90, 11.5, 5, 1 ], [ 92, 5.5, 7, 3 ], [ 94, 3.5, 9, 2 ], [ 96, 7.5, 11, 4 ], [ 98, 7.5, 0, 2 ], [ 100, 11.5, 2, 3 ], [ 102, 5.5, 4, 1 ], [ 104, 7.5, 5, 4 ], [ 106, 11.5, 7, 2 ], [ 108, 5.5, 9, 1 ], [ 110, 5.5, 11, 3 ], [ 112, 8.5, 0, 4 ], [ 114, 5.5, 2, 1 ], [ 116, 5.5, 4, 3 ], [ 118, 5.5, 5, 2 ], [ 120, 9.5, 7, 1 ], [ 122, 3.5, 9, 4 ], [ 124, 3.5, 11, 2 ], [ 126, 5.5, 0, 3 ], [ 128, 5.5, 2, 2 ], [ 130, 5.5, 4, 1 ], [ 132, 5.5, 5, 3 ], [ 134, 10, 7, 2 ], [ 136, 8, 9, 4 ], [ 138, 6, 11, 1 ], [ 140, 4, 0, 3 ] ] g = Gnuplot.Gnuplot(debug=1) g.title('REALLY COOL GRAPH') # (optional) g.xlabel('Start Time') g.ylabel('Duration') g('set data style linespoints') # give gnuplot an arbitrary command # Plot a list of (x, y) pairs (tuples or a Numeric array would # also be OK): #g.plot([[0,1.1], [1,5.8], [2,3.3], [3,4.2]]) g.plot(all) raw_input('Please press return to continue...\n') g.reset() # -- --------------- print '############### test splot ##################################' #g.splot(Gnuplot.Data(all, with='linesp', inline=1,)) g.splot(Gnuplot.Data(all, using=(1,), with='points', inline=1,)) #g.plot(Gnuplot.Data(d, with='lp 4 4')) #g.plot(Gnuplot.Data(d, cols=(0,1), inline=0), #Gnuplot.Data(d, cols=(0,2), inline=0)) #g.plot(Gnuplot.Data(d, cols=(0,1), inline=1), #Gnuplot.Data(d, cols=(0,2), inline=1)) #g.splot(Gnuplot.Data(all, with='linesp', inline=1)) # when executed, just run main if __name__ == '__main__': main() ------------ [snip] ---------------- |