From: Leonardo M. <lm...@ud...> - 2003-05-16 16:26:48
|
Hi Michael, Hola Fernando, All :-) I have done some tricks very similar to Fernando's independently, there is perhaps some real need for a set of simplified methods in gnuplot, to make its use a little friendlier. But I am not sure what is the best way to go. Add some methods ? Create a higher level interface to gnuplot ?. Don't know. I'll post my solutions briefly: [1] I inherit my own myGnuplot(Gnuplot) to extend Gnuplot as I need [2] I wrote an external functions to do quick plots In the first case I handle the terminal setting to postscrip, x, etc. I use reasonable (for my use) default values. So a ps plot goes like this: g.set_ps('filename.ps') g.plot(whatever) g.set_x() In the second case I am able to do quick plots from an interactive shell, just call qplot(y), or qplot(x,y), or plot(x,y1,y2) ... etc So, in short, I agree there is a need for the functionality Fernando is suggesting, the question is HOW to implement it. Thank you all for your time. Cheers, -- Leo PS: So, here is the code: [1] #### Gnuplot extension methods class myGnuplot(Gnuplot.Gnuplot): # [...] def set_eps(self, filename, options = 'enhanced color "Times-Roman" 22'): self('set terminal postscript eps ' + options) self('set output "' + filename + '"') def set_ps(self, filename, options = 'enhanced color "Times-Roman" 22'): self('set terminal postscript ' + options) self('set output "' + filename + '"') def set_x(self): self('set terminal x11') [2] #### quick plot function def qplot(x, y1=arange(0), y2=arange(0), y3=arange(0)): """ Quick plot Routine USAGE:: qplot(y) # plots y as a function of a vector [0,1,...,size(y)] qplot(x,y) # plots y(x) qplot(x,y1,y2) # plots y1(x) and y2(x) qplot(x,y1,y2,y3) # plots y1(x), y2(x) and y3(x) """ g = myGnuplot(persist=1, debug=1) g('set data style lines') if size(y1) == 0: d1 = Data(arange(size(x)), x) g.plot(d1, xlabel = "x", ylabel="y") elif size(y2) == 0: d1 = Data(x, y1, title="y1") g.plot(d1, xlabel = "x", ylabel="y") elif size(y3) == 0: d1 = Data(x, y1, title="y1") d2 = Data(x, y2, title="y2") g.plot(d1, d2, xlabel = "x", ylabel="y") else: d1 = Data(x, y1, title="y1") d2 = Data(x, y2, title="y2") d3 = Data(x, y3, title="y3") g.plot(d1, d2, d3, xlabel = "x", ylabel="y") |