Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.graphics.apps.gnuplot > #3871 > unrolled thread
| Started by | Chris Elvidge <chris@mshome.net> |
|---|---|
| First post | 2018-02-17 16:46 +0000 |
| Last post | 2018-02-23 18:50 +0100 |
| Articles | 9 — 3 participants |
Back to article view | Back to comp.graphics.apps.gnuplot
For loop not working as I expected Chris Elvidge <chris@mshome.net> - 2018-02-17 16:46 +0000
Re: For loop not working as I expected Karl Ratzsch <mail.kfr@gmx.net> - 2018-02-19 08:15 +0100
Re: For loop not working as I expected - but now solved Chris Elvidge <chris@mshome.net> - 2018-02-19 12:50 +0000
Re: For loop not working as I expected - but now solved Karl Ratzsch <mail.kfr@gmx.net> - 2018-02-19 14:26 +0100
Re: For loop not working as I expected - but now solved Chris Elvidge <chris@mshome.net> - 2018-02-19 14:22 +0000
Re: For loop not working as I expected - but now solved Karl Ratzsch <mail.kfr@gmx.net> - 2018-02-19 16:11 +0100
Re: For loop not working as I expected - but now solved Chris Elvidge <chris@mshome.net> - 2018-02-19 15:25 +0000
Re: For loop not working as I expected - but now solved Ethan A Merritt <EAMerritt@gmail.com> - 2018-02-21 22:38 -0800
Re: For loop not working as I expected - but now solved Karl Ratzsch <mail.kfr@gmx.net> - 2018-02-23 18:50 +0100
| From | Chris Elvidge <chris@mshome.net> |
|---|---|
| Date | 2018-02-17 16:46 +0000 |
| Subject | For loop not working as I expected |
| Message-ID | <p69m96$82n$1@dont-email.me> |
Hi all,
I'm a relative newcomer to gnuplot and can't find meaningful answers on
google. Gnuplot Version 5.0 patchlevel 5
This is a section of my gnuplot file:
F(n) = system("date -d\"-".sprintf('%d',n)." days\"
+\"/var/tmp/cpu-gpu-temp_%Y%m%d.dat\"")
#F(n) = system("date -d\"-".n." days\"
+\"/var/tmp/cpu-gpu-temp_%Y%m%d.dat\"")
do for [i=1:7] { print F(8-i); }
plot [j=1:7] F(8-j) u 1:4 w l lw 2 lc rgb "orange" t "CPU", '' u 1:5 w l
lw 2 lc rgb "green" t "GPU"
#plot [j=1:7] F(sprintf('%d',8-j)) u 1:4 w l lw 2 lc rgb "orange" t
"CPU", '' u 1:5 w l lw 2 lc rgb "green" t "GPU"
The print command gives the correct output whichever F(n) definition I use:
/var/tmp/cpu-gpu-temp_20180210.dat
/var/tmp/cpu-gpu-temp_20180211.dat
/var/tmp/cpu-gpu-temp_20180212.dat
/var/tmp/cpu-gpu-temp_20180213.dat
/var/tmp/cpu-gpu-temp_20180214.dat
/var/tmp/cpu-gpu-temp_20180215.dat
/var/tmp/cpu-gpu-temp_20180216.dat
but the plot command gives on of two errors:
either:
warning: encountered a string when expecting a number
Did you try to generate a file name using dummy variable x or y?
or:
internal error : STRING operator applied to non-STRING type
I've worked round it, but wondered where I am making mistakes in the
implied for loop in the plot command.
As an aside, feeding the file list from bash as $filelist, is there any
way of generating ARGn to be used as input file?
e.g. plot [i=1:ARGC] ARGi u 1:5 etc? All I get is ARGi is unknown/not a
file.
Thanks for any input.
Cheers
--
Chris Elvidge, England
[toc] | [next] | [standalone]
| From | Karl Ratzsch <mail.kfr@gmx.net> |
|---|---|
| Date | 2018-02-19 08:15 +0100 |
| Message-ID | <p6dti7$cpk$1@solani.org> |
| In reply to | #3871 |
Am 17.02.2018 um 17:46 schrieb Chris Elvidge: > plot [j=1:7] F(8-j) u 1:4 w l lw 2 lc rgb "orange" t "CPU", '' u 1:5 w l > lw 2 lc rgb "green" t "GPU" The second part of plot [i=1:4] fname(i) us 1:2, '' us 1:2 cannot work. '' just contains the last file name, in verbatim, that was in the plot command. It doesn't expect a function, and especially cannot contain the whole iteration. The error message could be a bit clearer, but obviously nobody thought of the specific misuse you tried. ;-) You have to repeat the iteration : plot [i=1:4] fname(i) us 1:2 w lc i, for [i=1:4] fname(i) us 1:2 w lc i Best, Karl
[toc] | [prev] | [next] | [standalone]
| From | Chris Elvidge <chris@mshome.net> |
|---|---|
| Date | 2018-02-19 12:50 +0000 |
| Subject | Re: For loop not working as I expected - but now solved |
| Message-ID | <p6eh76$i4j$1@dont-email.me> |
| In reply to | #3874 |
On 19/02/2018 07:15 am, Karl Ratzsch wrote:
> Am 17.02.2018 um 17:46 schrieb Chris Elvidge:
>
>> plot [j=1:7] F(8-j) u 1:4 w l lw 2 lc rgb "orange" t "CPU", '' u 1:5 w l
>> lw 2 lc rgb "green" t "GPU"
>
> The second part of
>
> plot [i=1:4] fname(i) us 1:2, '' us 1:2
>
> cannot work. '' just contains the last file name, in verbatim, that was
> in the plot command. It doesn't expect a function, and especially cannot
> contain the whole iteration. The error message could be a bit clearer,
> but obviously nobody thought of the specific misuse you tried. ;-)
>
> You have to repeat the iteration :
>
> plot [i=1:4] fname(i) us 1:2 w lc i, for [i=1:4] fname(i) us 1:2 w lc i
>
>
> Best, Karl
>
Sorry Karl, that didn't work either. But thanks for pointing out the
need for the second "for [i=1:4]" bit.
However, this did work:
F(n) = system("date -d\"-".n." days\"
\"+/var/tmp/cpu-gpu-temp_%Y%m%d.dat\"")
plot for [j=1:7] F(8-j) u 1:4 w l lw 2 lc rgb "orange" noti, for [j=1:7]
F(8-j) u 1:5 w l lw 2 lc rgb "web-green" noti
Note the extra "for" after the plot command. Could this be a bug in the
manual?
Strangely, with "plot for" and '' as the second file specifier, I get
all the files for the first plot, but only the last file for the second
plot.
Cheers
--
Chris Elvidge, England
[toc] | [prev] | [next] | [standalone]
| From | Karl Ratzsch <mail.kfr@gmx.net> |
|---|---|
| Date | 2018-02-19 14:26 +0100 |
| Subject | Re: For loop not working as I expected - but now solved |
| Message-ID | <p6ejat$rqg$1@solani.org> |
| In reply to | #3875 |
Am 19.02.2018 um 13:50 schrieb Chris Elvidge: > plot for [j=1:7] F(8-j) u 1:4 w l lw 2 lc rgb "orange" noti, for [j=1:7] > F(8-j) u 1:5 w l lw 2 lc rgb "web-green" noti > > Note the extra "for" after the plot command. Could this be a bug in the > manual? Sorry, I totally overlooked that! Of course it needs to be "for [:]" in both the first and the second subplot. Where does the manual say otherwise? That would be an error and you should file a bug report. The command plot [j=1:7] dataf ... should assign the value 1 to "j", and make a plot with abscissa range[1:7]. (The assignment is not actually done, but the parser also doesn't throw an error. It arguably should do one or the other, so that's a small bug.) > Strangely, with "plot for" and '' as the second file specifier, I get > all the files for the first plot, but only the last file for the second > plot. That's the expected behaviour. The special filename '' just contains the last file(name) that was plotted, not the whole iteration. Karl
[toc] | [prev] | [next] | [standalone]
| From | Chris Elvidge <chris@mshome.net> |
|---|---|
| Date | 2018-02-19 14:22 +0000 |
| Subject | Re: For loop not working as I expected - but now solved |
| Message-ID | <p6emic$npo$1@dont-email.me> |
| In reply to | #3876 |
On 19/02/2018 01:26 pm, Karl Ratzsch wrote: > Am 19.02.2018 um 13:50 schrieb Chris Elvidge: > >> plot for [j=1:7] F(8-j) u 1:4 w l lw 2 lc rgb "orange" noti, for [j=1:7] >> F(8-j) u 1:5 w l lw 2 lc rgb "web-green" noti >> >> Note the extra "for" after the plot command. Could this be a bug in the >> manual? > > Sorry, I totally overlooked that! Of course it needs to be "for [:]" in > both the first and the second subplot. Where does the manual say > otherwise? That would be an error and you should file a bug report. > > The command > > plot [j=1:7] dataf ... > > should assign the value 1 to "j", and make a plot with abscissa > range[1:7]. (The assignment is not actually done, but the parser also > doesn't throw an error. It arguably should do one or the other, so > that's a small bug.) I put it down to my misreading (i.e. not fully understanding what is going on) of this (first example) where 'plot [-10:10]' is used; 'for' is not mentioned: http://gnuplot.sourceforge.net/demo_svg_5.0/simple.html Anyhow, thanks for the pointers. With any luck my skills will improve. Cheers -- Chris Elvidge, England
[toc] | [prev] | [next] | [standalone]
| From | Karl Ratzsch <mail.kfr@gmx.net> |
|---|---|
| Date | 2018-02-19 16:11 +0100 |
| Subject | Re: For loop not working as I expected - but now solved |
| Message-ID | <p6epe8$g0$1@solani.org> |
| In reply to | #3877 |
Am 19.02.2018 um 15:22 schrieb Chris Elvidge:
> I put it down to my misreading (i.e. not fully understanding what is
> going on) of this (first example) where 'plot [-10:10]' is used; 'for'
> is not mentioned:
>
> http://gnuplot.sourceforge.net/demo_svg_5.0/simple.html
The full syntax for plot iteration is this:
plot {[xmin:xmax] {[ymin:ymax]}} for [i=a:b] F(x)
, where everything in curly brackets is optional. Try
plot [-2:2] [-5:10] x**2
against
plot for [i=0:3] x**i
xmin,xmax,ymin,ymax just give the length of the axes, while iteration
needs the "for" keyword.
[toc] | [prev] | [next] | [standalone]
| From | Chris Elvidge <chris@mshome.net> |
|---|---|
| Date | 2018-02-19 15:25 +0000 |
| Subject | Re: For loop not working as I expected - but now solved |
| Message-ID | <p6eq9d$ibo$1@dont-email.me> |
| In reply to | #3878 |
On 19/02/2018 03:11 pm, Karl Ratzsch wrote:
> Am 19.02.2018 um 15:22 schrieb Chris Elvidge:
>
>> I put it down to my misreading (i.e. not fully understanding what is
>> going on) of this (first example) where 'plot [-10:10]' is used; 'for'
>> is not mentioned:
>>
>> http://gnuplot.sourceforge.net/demo_svg_5.0/simple.html
>
>
> The full syntax for plot iteration is this:
>
> plot {[xmin:xmax] {[ymin:ymax]}} for [i=a:b] F(x)
>
> , where everything in curly brackets is optional. Try
>
> plot [-2:2] [-5:10] x**2
>
> against
>
> plot for [i=0:3] x**i
>
> xmin,xmax,ymin,ymax just give the length of the axes, while iteration
> needs the "for" keyword.
>
Got it now - I think!
Cheers again
--
Chris Elvidge, England
[toc] | [prev] | [next] | [standalone]
| From | Ethan A Merritt <EAMerritt@gmail.com> |
|---|---|
| Date | 2018-02-21 22:38 -0800 |
| Subject | Re: For loop not working as I expected - but now solved |
| Message-ID | <p6logm$ci3$1@dont-email.me> |
| In reply to | #3876 |
Karl Ratzsch wrote:
> The command
>
> plot [j=1:7] dataf ...
>
> should assign the value 1 to "j", and make a plot with abscissa
> range[1:7]. (The assignment is not actually done, but the parser also
> doesn't throw an error. It arguably should do one or the other, so
> that's a small bug.)
No bug there. The dependent variable becomes j rather than x,
allowing you to say:
plot [theta=1:7] sin(theta)
Ethan
[toc] | [prev] | [next] | [standalone]
| From | Karl Ratzsch <mail.kfr@gmx.net> |
|---|---|
| Date | 2018-02-23 18:50 +0100 |
| Subject | Re: For loop not working as I expected - but now solved |
| Message-ID | <p6pk8d$13p$1@solani.org> |
| In reply to | #3884 |
Am 22.02.2018 um 07:38 schrieb Ethan A Merritt: > Karl Ratzsch wrote: > > >> The command >> >> plot [j=1:7] dataf ... >> >> should assign the value 1 to "j", and make a plot with abscissa >> range[1:7]. (The assignment is not actually done, but the parser also >> doesn't throw an error. It arguably should do one or the other, so >> that's a small bug.) > > No bug there. The dependent variable becomes j rather than x, > allowing you to say: > > plot [theta=1:7] sin(theta) Yes, of course. Sorry for the noise. Karl
[toc] | [prev] | [standalone]
Back to top | Article view | comp.graphics.apps.gnuplot
csiph-web