Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.graphics.apps.gnuplot > #2553 > unrolled thread
| Started by | Kalin Kozhuharov <me.kalin@gmail.com> |
|---|---|
| First post | 2014-08-19 11:57 -0700 |
| Last post | 2014-08-20 23:02 -0700 |
| Articles | 7 — 3 participants |
Back to article view | Back to comp.graphics.apps.gnuplot
difficult for loop synax :-| Kalin Kozhuharov <me.kalin@gmail.com> - 2014-08-19 11:57 -0700
Re: difficult for loop synax :-| Ethan A Merritt <EAMerritt@gmail.com> - 2014-08-19 18:03 -0700
Re: difficult for loop synax :-| Kalin Kozhuharov <me.kalin@gmail.com> - 2014-08-19 23:15 -0700
Re: difficult for loop synax :-| Ethan A Merritt <sfeam@users.sourceforge.net> - 2014-08-20 10:15 -0700
Re: difficult for loop synax :-| Kalin Kozhuharov <me.kalin@gmail.com> - 2014-08-20 11:50 -0700
Re: difficult for loop synax :-| Ethan A Merritt <EAMerritt@gmail.com> - 2014-08-20 17:50 -0700
Re: difficult for loop synax :-| Kalin Kozhuharov <me.kalin@gmail.com> - 2014-08-20 23:02 -0700
| From | Kalin Kozhuharov <me.kalin@gmail.com> |
|---|---|
| Date | 2014-08-19 11:57 -0700 |
| Subject | difficult for loop synax :-| |
| Message-ID | <9bc28e9e-f776-4407-8acc-f0bc7a964bcf@googlegroups.com> |
I have been trying to plot two dependent functions per single for loop, but cannot get the syntax right...
This works but is a lot of typing and if I don't know the number of arguments cannot be expressed:
plot C=1, sin(C*x) w l, C=2, sin(C*x) w l, C=3, sin(C*x) w l;
Any ideas?
This works:
plot for [n in "1 2 3"] n*x, for [n in "1 2 3"] sin(n*x) w l;
but those are independent functions, so 3 times n*x is plotted, then 3 times sin(n*x) in that order
I need something like
plot for [n in "1 2 3"] {C=n, sin(C*x) w l};
i.e. set some parameter by a function, then plot something, then evaluate the parameter again, then plot second function...
Fiddling with multiplot is hard it seems, need to hardcode linestyles, etc.
Kalin.
[toc] | [next] | [standalone]
| From | Ethan A Merritt <EAMerritt@gmail.com> |
|---|---|
| Date | 2014-08-19 18:03 -0700 |
| Message-ID | <lt0s51$jbh$1@dont-email.me> |
| In reply to | #2553 |
Kalin Kozhuharov wrote:
> I have been trying to plot two dependent functions per single for
> loop, but cannot get the syntax right...
>
> This works but is a lot of typing and if I don't know the number of
> arguments cannot be expressed:
>
> plot C=1, sin(C*x) w l, C=2, sin(C*x) w l, C=3, sin(C*x) w l;
>
> Any ideas?
Please clarify. I see only a single function there, evaluated
three times. Where is the second dependent function?
>
> This works:
>
> plot for [n in "1 2 3"] n*x, for [n in "1 2 3"] sin(n*x) w l;
>
> but those are independent functions, so 3 times n*x is plotted, then 3
> times sin(n*x) in that order
>
> I need something like
>
> plot for [n in "1 2 3"] {C=n, sin(C*x) w l};
> i.e. set some parameter by a function, then plot something, then
> evaluate the parameter again, then plot second function...
I still see only a single function.
That command appears to be equivalent to
plot for [C=1:3] sin(C*x)
You must have some additional step in mind, I guess?
> Fiddling with multiplot is hard it seems, need to hardcode linestyles,
> etc.
>
> Kalin.
[toc] | [prev] | [next] | [standalone]
| From | Kalin Kozhuharov <me.kalin@gmail.com> |
|---|---|
| Date | 2014-08-19 23:15 -0700 |
| Message-ID | <7d92eab8-bceb-49bb-80aa-ff7834bc9a73@googlegroups.com> |
| In reply to | #2554 |
On Wednesday, August 20, 2014 10:03:27 AM UTC+9, Ethan A Merritt wrote:
> Kalin Kozhuharov wrote:
> > I have been trying to plot two dependent functions per single for
> > loop, but cannot get the syntax right...
> > This works but is a lot of typing and if I don't know the number of
> > arguments cannot be expressed:
>
> > plot C=1, sin(C*x) w l, C=2, sin(C*x) w l, C=3, sin(C*x) w l;
>
> Please clarify. I see only a single function there, evaluated
> three times. Where is the second dependent function?
>
Well, may be I oversimplified it, but the real thing is too complex anyway.
What about this:
reset; f1(x) = (C=1.134324*x,0); f2(x) = sin(C*x); set xrange [0:3.14];
plot a=f1(1), f2(x) title "n=1", a=f1(2), f2(x) title "n=2" , a=f1(3), f2(x) title "n=3";
How can I turn it into something like:
N="1 2 3"; plot for [n in N] a=f1(n), f2(x) title "n=" . n;
so that it produces the same result (all plots on same graph, automatically linestyled) when I don't know N. Currently this produces only one graph when n=3, because the for loop is only evaluated till the ",", then f2(x) is plotted once. I need some kind of syntactic "brackets".
I also tried:
N="1 2 3"; do for [n in N] {plot a=f1(n), f2(x) title "n=" . n; pause .2; };
and saw how the plot is being generated, then overwritten by the next call of plot.
Cheers,
Kalin.
[toc] | [prev] | [next] | [standalone]
| From | Ethan A Merritt <sfeam@users.sourceforge.net> |
|---|---|
| Date | 2014-08-20 10:15 -0700 |
| Message-ID | <lt2l49$hgn$1@dont-email.me> |
| In reply to | #2555 |
Kalin Kozhuharov wrote:
> On Wednesday, August 20, 2014 10:03:27 AM UTC+9, Ethan A Merritt wrote:
>> Kalin Kozhuharov wrote:
>> > I have been trying to plot two dependent functions per single for
>> > loop, but cannot get the syntax right...
>> > This works but is a lot of typing and if I don't know the number of
>> > arguments cannot be expressed:
>>
>> > plot C=1, sin(C*x) w l, C=2, sin(C*x) w l, C=3, sin(C*x) w l;
>>
>> Please clarify. I see only a single function there, evaluated
>> three times. Where is the second dependent function?
>>
> Well, may be I oversimplified it, but the real thing is too complex
> anyway. What about this:
>
> reset; f1(x) = (C=1.134324*x,0); f2(x) = sin(C*x); set xrange [0:3.14];
> plot a=f1(1), f2(x) title "n=1", a=f1(2), f2(x) title "n=2" , a=f1(3),
> f2(x) title "n=3";
It is still not clear what you are aiming for.
The sequence of commands above does not make sense.
The function f1(x) is never plotted, so it plays no role except for
its side effect of setting C to a constant.
A simpler way to write it would be
f1(x) = 1.134324*x
plot for [n=1:3] sin(f1(n)*x) title sprintf("n=%d",n)
> How can I turn it into something like:
> N="1 2 3"; plot for [n in N] a=f1(n), f2(x) title "n=" . n;
> when I don't know N
Same as above, replacing 3 with N
plot for [n=1:N] ...
Of course N still has to come from somewhere, I assume from some
earlier part of the script.
> so that it produces the same result (all plots on same graph,
> automatically linestyled) when I don't know N. Currently this produces
> only one graph when n=3, because the for loop is only evaluated till the
> ",", then f2(x) is plotted once. I need some kind of syntactic "brackets".
>
> I also tried:
> N="1 2 3"; do for [n in N] {plot a=f1(n), f2(x) title "n=" . n; pause .2;
> }; and saw how the plot is being generated, then overwritten by the next
> call of plot.
>
> Cheers,
> Kalin.
--
Ethan A Merritt
[toc] | [prev] | [next] | [standalone]
| From | Kalin Kozhuharov <me.kalin@gmail.com> |
|---|---|
| Date | 2014-08-20 11:50 -0700 |
| Message-ID | <9066cc28-d4c2-4bb6-a081-4ce966222a7e@googlegroups.com> |
| In reply to | #2556 |
Hello Ethan,
Thank you for your time! I was trying to make self-contained example, but because it was simple enough you "optimized" it ;-) "Premature optimization is the root of all evil", said D. Knuth :-D
On Thursday, August 21, 2014 2:15:51 AM UTC+9, Ethan A Merritt wrote:
>> Well, may be I oversimplified it, but the real thing is too complex
>> anyway. What about this:
>>
>> reset; f1(x) = (C=1.134324*x,0); f2(x) = sin(C*x); set xrange [0:3.14];
>> plot a=f1(1), f2(x) title "n=1", a=f1(2), f2(x) title "n=2" , a=f1(3),
>> f2(x) title "n=3";
>
> It is still not clear what you are aiming for.
> The sequence of commands above does not make sense.
>
> The function f1(x) is never plotted, so it plays no role except for
> its side effect of setting C to a constant.
>
Well, yes I'd have to admit I am using side-effects here.
And my code is turning to a small mess because I am trying to have gnuplot do statistics in-line, instead of preprocessing the data.
My current code is here: https://github.com/thinrope/fixed_sensor_visualization/blob/master/timeplot_all.gpl#L26
plot for [ID in IDs] "tmp/" . ID . ".data" u 1:2 axes x1y2 w l lw 2 title graph_title(ID);
What I wanted to do is add another SMA filter on each datafile (or 2 with different window) and still have it plot similar graph.
so having defined SMA as in https://github.com/thinrope/fixed_sensor_visualization/blob/master/timeplot.gpl#L46 I was planning to write something along:
plot for [ID in IDs] a=sma_24_init(0), "tmp/" . ID . ".data" u 1:(sma_24($2)) axes x1y2 w l lw 2 title graph_title(ID);
IDs are list of numbers coming form the environment/Makefile, but can be strings.
May be possible with `set table` and `do for [ID in IDs]{init; plot;}` but I'd rather avoid it.
Alternatively, something along
init_OK=0; f3(x,n) = (init_OK ? a=f1(n): 0, f2(x));
plot for [n=1:3] a=f3(x,n);
undefined variable: x
:-|
Kalin.
[toc] | [prev] | [next] | [standalone]
| From | Ethan A Merritt <EAMerritt@gmail.com> |
|---|---|
| Date | 2014-08-20 17:50 -0700 |
| Message-ID | <lt3fpe$550$1@dont-email.me> |
| In reply to | #2557 |
Kalin Kozhuharov wrote:
> Hello Ethan,
>
> Thank you for your time! I was trying to make self-contained example,
> but because it was simple enough you "optimized" it ;-) "Premature
> optimization is the root of all evil", said D. Knuth :-D
>
> On Thursday, August 21, 2014 2:15:51 AM UTC+9, Ethan A Merritt wrote:
>>> Well, may be I oversimplified it, but the real thing is too complex
>>> anyway. What about this:
>>>
>>> reset; f1(x) = (C=1.134324*x,0); f2(x) = sin(C*x); set xrange
>>> [0:3.14]; plot a=f1(1), f2(x) title "n=1", a=f1(2), f2(x) title
>>> "n=2" , a=f1(3), f2(x) title "n=3";
>>
>> It is still not clear what you are aiming for.
>> The sequence of commands above does not make sense.
>>
>> The function f1(x) is never plotted, so it plays no role except for
>> its side effect of setting C to a constant.
>>
> Well, yes I'd have to admit I am using side-effects here.
> And my code is turning to a small mess because I am trying to have
> gnuplot do statistics in-line, instead of preprocessing the data.
>
> My current code is here:
> https://github.com/thinrope/fixed_sensor_visualization/blob/master/timeplot_all.gpl#L26
>
> plot for [ID in IDs] "tmp/" . ID . ".data" u 1:2 axes x1y2 w l lw 2
> title graph_title(ID);
>
> What I wanted to do is add another SMA filter on each datafile (or 2
> with different window) and still have it plot similar graph.
>
> so having defined SMA as in
> https://github.com/thinrope/fixed_sensor_visualization/blob/master/timeplot.gpl#L46
> I was planning to write something along:
>
> plot for [ID in IDs] a=sma_24_init(0), "tmp/" . ID . ".data" u
> 1:(sma_24($2)) axes x1y2 w l lw 2 title graph_title(ID);
I think that statement would work if you just remove the unnecessary comma
after the definition a=<something>.
Doesn't it?
Ethan
> IDs are list of numbers coming form the environment/Makefile, but can
> be strings.
>
> May be possible with `set table` and `do for [ID in IDs]{init; plot;}`
> but I'd rather avoid it.
>
>
> Alternatively, something along
>
> init_OK=0; f3(x,n) = (init_OK ? a=f1(n): 0, f2(x));
> plot for [n=1:3] a=f3(x,n);
> undefined variable: x
> :-|
>
> Kalin.
[toc] | [prev] | [next] | [standalone]
| From | Kalin Kozhuharov <me.kalin@gmail.com> |
|---|---|
| Date | 2014-08-20 23:02 -0700 |
| Message-ID | <b0e948d3-055b-4945-88fe-3e9afb833459@googlegroups.com> |
| In reply to | #2558 |
On Thursday, August 21, 2014 9:50:52 AM UTC+9, Ethan A Merritt wrote: >> plot for [ID in IDs] a=sma_24_init(0), "tmp/" . ID . ".data" u >> 1:(sma_24($2)) axes x1y2 w l lw 2 title graph_title(ID); > I think that statement would work if you just remove the unnecessary comma > after the definition a=<something>. > > Doesn't it? > LoL, LoL, LoL! Yes it works now. It was _only_ the extra coma that broke it... Thank you very much. The data is now better visualized in http://gamma.tar.bz/nGeigies/ Kalin.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.graphics.apps.gnuplot
csiph-web