|
From: <pl...@pi...> - 2007-05-08 07:20:30
|
On Tue, 08 May 2007 01:51:34 +0200, Ethan Merritt = <merritt@u.washington.edu> wrote: > The SourceForge end of the gnuplot-bugs mailing list is currently brok= en. > I found this posting via gmane.org (under "bugs") but it doesn't reall= y > belong there, so I'm copying it to the developers list with a reply. Hi Ethan, thanks very much for picking this up. That seems quite close to what I w= as = requesting. I extended your example to pick up the x value of the ymax a= s = well. The plot gives the sample-and-hold plot as expected. Proof of = principle. Nice one. It would be quite a simple extention to do a trapezoidal area under grap= h = or the mean. The nice thing is this can be limitted by setting the range before plot.= = This is a nice quick solution that avoids quite a bit of effort messing = = about with external scripts for simple stuff like this. A nice addition.= set xdata time set timefmt "%H:%M" set xr ["10:15":"18:30"] xmax=3D0;ymax=3D0; max(x,y)=3Dassign("ymax",(ymax<y)?y+0. * assign("xmax",x):ymax ); set label "max was here" at "11:00",ymax/10; plot datafile using 1:(P( Th4($3-2.0) - Th5($2) )) axes x1y2 with = lines s f t "useful power" \ , datafile using 1:(max(column(1),P( Th4($3-2.0) - Th5($2) ))) axes = x1y2 with lines s f t "s/hold" \ My initial task with this was to put a label on the graph at the max poi= nt. This presents me with some small issues remaining to be solved: 1. My xdata is time format , I imagine your patch does not try to fit al= l = cases but in assigning the x value it gets truncated to the nearest hour= , = 12:45 becomes 12.0 2. my inexperience with gnuplot, it seems that if I try to set a label = after the plot command (which I need to do for xmax,ymax) it does not = show. The same command before plot command does work but it's at (0,0). I'm sure gnuplot users (ingenious as they are) will find 101 neat tricks= = to do with the new command , it opens up all sorts of possibilities. Many thanks. >>>>>>>>>> Synopsis: The suggestion is to allow assignment to a variable inside an expression. This may be useful in order to collect statistics about data points as they are read in Response: I have attached a small patch that implements a new user-visible function: assign("VAR", <expression>) It assigns the current value of the expression to a variable named VAR. NB: this is the _name_ of the variable, not the variable itself. Example: MAX =3D -999 update_max(x) =3D assign("MAX", x > MAX ? x : MAX) plot <foo> using 1:($2 + 0. * update_max($2)) print "Maximum data value plotted was", MAX Comments: I'm not sure this will actually accomplish what you want, but please try it out and let us know. If you use this inside a "using" clause, it will slow down data input. For large data files the slowdown is likely to be noticeable. For the use above, it would probably be more convenient to have the update_max(x) function return the current value of x rather than the updated maximum. It's not clear to me how best to achieve that. %%%%%%%% begin forwarded message %%%%%%%%% From: <plotter <at> piments.com> Subject: feature request Newsgroups: gmane.comp.graphics.gnuplot.bugs I have been trying to trick gnuplot into doing some simple tasks it does= not seem possible to do but which could be immensely useful. to judge by comp.graphics.apps.gnuplot it seems that there are certain basic tasks that are frequently requested and get a reply along the line= s of "gnuplot is not for number crunching". Fine. Gnuplot is a plotting program, not a data processing package but there are an number of trivial tasks like calculating a mean or finding the max of values *calculated* by gnuplot that cant currently be done. Tasks like this are far less complex than function fitting do data or plotting with spline interpolation and would be very valuable in the context of outputting data to a graph. eg how to put a label at the max point of the data. Definately a plottin= g task and hardly "number crunching" but currently it seems I have do this= simple task in an external script. Worse, if I do some fitting and expression evaluation in the plot comman= d , I have to duplicate it all to a table, call an external script and the= n read in a new file to get the value of the max or mean value of y. all I really need is a means to assign one tiny little variable during plot (directly or from a within a fn ) consider the following that will plot a "sample and hold": xmax=3D0; max(x)=3D( (xmax<x)?(xmax=3Dx):xmax ); plot "150tank-txC.data" using 1:(Th6($4)) with lines t "panel out" \ , "150tank-txC.data" using 1:(max(Th6($4))) with lines t "s/h" ; Currently not possible since function parser will not allow C style 'assignment returns a value'. A similar technique could find the min , max, mean or area under graph; = in fact it opens a whole range of possibilities that are frequently request= ed on the list. So how much effort is it? Well without going to the extent of supporting procedure calls from with= plot command , adding the above parsing of C style assignments would be simple to add and open the door to some very useful techniques. I hope you will find it worth considering. Kind regards. %%%%%%%% begin forwarded message %%%%%%%%% |