|
From: gbliu <goo...@gm...> - 2011-11-18 09:43:55
|
Dear all:
These years gnuplot becomes more and more powerful. In sense, it's a
quasi-programming-language. String variable is supported since ver4.0, and {}
blocks and loops are supported in ver4.5. But a basic function, array, is still
not supported now. I think this is highly needed, especially when loops are
supported.
------------------------
e.g.
I have a data file with many columns, but want to plot only some columns, say,
column 2, 3,6,7,9,15,24. And the lengeds for each column differ. Now, I can only
use the command as follow:
plot 'data' u 1:2 title '...', '' u 1:3 title '...', '' u 1:6 title '...',\
'' u 1:7 title '...', '' u 1:9 title '...', '' u 1:15 title '...',\
'' u 1:24 title '...'
Although gnuplot support "plot for [i=...]" now, but it cannot be used here,
because the column numbers is not regular. In this case, array is needed to
simplify the plot command.
Suppose there are two arrays, col and str:
col[1]=2; str[1]='...'
col[2]=3; str[2]='...'
col[3]=6; str[3]='...'
col[4]=7; str[4]='...'
col[5]=9; str[5]='...'
col[6]=15; str[6]='...'
col[7]=24; str[7]='...'
now, I can use the following more concise command:
plot for [i=1:7] 'data' u 1:(column(col[i])) title str[i]
------------------------
Therefore, array is highly suggested to be supportted by gnuplot!
Yours, faithfully
gbliu
|
|
From: Ethan A M. <sf...@us...> - 2011-11-18 20:32:11
|
On Friday, November 18, 2011 01:43:29 am gbliu wrote:
> Dear all:
>
> These years gnuplot becomes more and more powerful. In sense, it's a
> quasi-programming-language. String variable is supported since ver4.0, and {}
> blocks and loops are supported in ver4.5. But a basic function, array, is still
> not supported now. I think this is highly needed, especially when loops are
> supported.
>
> ------------------------
> e.g.
>
> I have a data file with many columns, but want to plot only some columns, say,
> column 2, 3,6,7,9,15,24. And the lengeds for each column differ. Now, I can only
> use the command as follow:
>
>
> plot 'data' u 1:2 title '...', '' u 1:3 title '...', '' u 1:6 title '...',\
> '' u 1:7 title '...', '' u 1:9 title '...', '' u 1:15 title '...',\
> '' u 1:24 title '...'
>
> Although gnuplot support "plot for [i=...]" now, but it cannot be used here,
> because the column numbers is not regular. In this case, array is needed to
> simplify the plot command.
Array support has been suggested before, but no one has stepped up to
do the work :-)
In your particular case it is possible to use the existing syntax
plot for [COL in "2 3 6 7 9 15 24"] 'data' using 1:(column(int(COL))
Generalizing this a little bit, you could even do
COL = "2 3 6 7 9 15 24"
TITLE = "title2 title3 title6 title7 title9 title15 title24"
plot for [i=1:7] 'data' using 1:(column(int(word(COL,i)))) title word(TITLE,i)
Ethan
>
> Suppose there are two arrays, col and str:
> col[1]=2; str[1]='...'
> col[2]=3; str[2]='...'
> col[3]=6; str[3]='...'
> col[4]=7; str[4]='...'
> col[5]=9; str[5]='...'
> col[6]=15; str[6]='...'
> col[7]=24; str[7]='...'
>
> now, I can use the following more concise command:
>
> plot for [i=1:7] 'data' u 1:(column(col[i])) title str[i]
>
> ------------------------
>
> Therefore, array is highly suggested to be supportted by gnuplot!
>
> Yours, faithfully
>
> gbliu
>
|
|
From: gbliu <goo...@gm...> - 2011-11-19 16:46:41
|
Thank you for your tips. But the using of word() function is limitted
to "words".
If a key title is a string with spaces, then the word() function can not
be used.
Only array function can solve the problem perfectly.
In version 4.5, the loop and block are supported as new features:
7 * NEW syntax supporting multi-line blocks of code delimited by curly
braces
8 if (<cond>) { ... } else { ... }
9 do for [...] { ... }
10 while (<cond>) { ... }
Now that loop is supportted, the absence of array will limit the
application of loop in significant measure.
So, I still highly suggest developers to add array support in the future.
gbliu
? 2011/11/19 4:30, Ethan A Merritt ??:
> On Friday, November 18, 2011 01:43:29 am gbliu wrote:
>> Dear all:
>>
>> These years gnuplot becomes more and more powerful. In sense, it's a
>> quasi-programming-language. String variable is supported since ver4.0, and {}
>> blocks and loops are supported in ver4.5. But a basic function, array, is still
>> not supported now. I think this is highly needed, especially when loops are
>> supported.
>>
>> ------------------------
>> e.g.
>>
>> I have a data file with many columns, but want to plot only some columns, say,
>> column 2, 3,6,7,9,15,24. And the lengeds for each column differ. Now, I can only
>> use the command as follow:
>>
>>
>> plot 'data' u 1:2 title '...', '' u 1:3 title '...', '' u 1:6 title '...',\
>> '' u 1:7 title '...', '' u 1:9 title '...', '' u 1:15 title '...',\
>> '' u 1:24 title '...'
>>
>> Although gnuplot support "plot for [i=...]" now, but it cannot be used here,
>> because the column numbers is not regular. In this case, array is needed to
>> simplify the plot command.
> Array support has been suggested before, but no one has stepped up to
> do the work :-)
>
> In your particular case it is possible to use the existing syntax
>
> plot for [COL in "2 3 6 7 9 15 24"] 'data' using 1:(column(int(COL))
>
> Generalizing this a little bit, you could even do
>
> COL = "2 3 6 7 9 15 24"
> TITLE = "title2 title3 title6 title7 title9 title15 title24"
>
> plot for [i=1:7] 'data' using 1:(column(int(word(COL,i)))) title word(TITLE,i)
>
>
> Ethan
>
>
>> Suppose there are two arrays, col and str:
>> col[1]=2; str[1]='...'
>> col[2]=3; str[2]='...'
>> col[3]=6; str[3]='...'
>> col[4]=7; str[4]='...'
>> col[5]=9; str[5]='...'
>> col[6]=15; str[6]='...'
>> col[7]=24; str[7]='...'
>>
>> now, I can use the following more concise command:
>>
>> plot for [i=1:7] 'data' u 1:(column(col[i])) title str[i]
>>
>> ------------------------
>>
>> Therefore, array is highly suggested to be supportted by gnuplot!
>>
>> Yours, faithfully
>>
>> gbliu
>>
>
|
|
From: sfeam (E. Merritt) <eam...@gm...> - 2011-11-23 02:13:23
|
On Friday, 18 November 2011, gbliu wrote:
> Dear all:
>
> These years gnuplot becomes more and more powerful. In sense, it's a
> quasi-programming-language. String variable is supported since ver4.0, and {}
> blocks and loops are supported in ver4.5. But a basic function, array, is still
> not supported now. I think this is highly needed, especially when loops are
> supported.
>
> ------------------------
> e.g.
>
> I have a data file with many columns, but want to plot only some columns, say,
> column 2, 3,6,7,9,15,24. And the lengeds for each column differ. Now, I can only
> use the command as follow:
>
>
> plot 'data' u 1:2 title '...', '' u 1:3 title '...', '' u 1:6 title '...',\
> '' u 1:7 title '...', '' u 1:9 title '...', '' u 1:15 title '...',\
> '' u 1:24 title '...'
>
> Although gnuplot support "plot for [i=...]" now, but it cannot be used here,
> because the column numbers is not regular. In this case, array is needed to
> simplify the plot command.
>
> Suppose there are two arrays, col and str:
> col[1]=2; str[1]='...'
> col[2]=3; str[2]='...'
> col[3]=6; str[3]='...'
> col[4]=7; str[4]='...'
> col[5]=9; str[5]='...'
> col[6]=15; str[6]='...'
> col[7]=24; str[7]='...'
>
> now, I can use the following more concise command:
>
> plot for [i=1:7] 'data' u 1:(column(col[i])) title str[i]
I can imagine numerical uses for arrays, but your example seems to
be just a request for an easier way to order variable names.
The following works currently, for example:
col1 = 2; str1 = 'title 1 with multiple words'
col2 = 3; str2 = 'title 2 etc'
col3 = 6; str3 = 'title 3'
...
COLUMN = "col"
TITLE = "str"
plot for [i=1:7] 'data' u 1:(column(value(COLUMN.i))) title TITLE.i
I grant you that column(value(COLUMN.i)) is a bit awkward compared
to just col[i], but if we cleaned up that syntax a bit would it address
your needs? I really don't see anything in this particular request that
requires an array in the usual mathematical sense.
|
|
From: gbliu <goo...@gm...> - 2011-11-23 07:22:22
|
? 2011/11/23 10:13, sfeam (Ethan Merritt) ??:
> I can imagine numerical uses for arrays, but your example seems to
> be just a request for an easier way to order variable names.
> The following works currently, for example:
>
> col1 = 2; str1 = 'title 1 with multiple words'
> col2 = 3; str2 = 'title 2 etc'
> col3 = 6; str3 = 'title 3'
> ...
> COLUMN = "col"
> TITLE = "str"
>
> plot for [i=1:7] 'data' u 1:(column(value(COLUMN.i))) title TITLE.i
>
> I grant you that column(value(COLUMN.i)) is a bit awkward compared
> to just col[i], but if we cleaned up that syntax a bit would it address
> your needs? I really don't see anything in this particular request that
> requires an array in the usual mathematical sense.
Thanks for your reply. The value() function can indeed solve my
problem. It can be used to simulate the functionality of array,
combined with eval. e.g.
i=3
assign a value: eval "a".i."=3" <------> a[i]=3
access the value: value("a".i) <------> a[i]
It is only the introduction of value() in the devel. version that can do
this. I just know it after your reply. I have been working with the
4.4 version, which is the reason why no scheme can work and I need array
functionality. But to tell the truth. this is only an awkward
alternative to simulate array, which is not graceful and concise. I
still hope array can be supported in the future, which is not a bad
thing after all. Anyway, it works now. So the need of array is not that
urgent.
By the way, there seems to be a small bug:
gnuplot> s="a"
gnuplot> i=1
gnuplot> pr "a".1
^
';' expected
gnuplot> pr "a".i
a1
gnuplot> pr s.1
^
';' expected
gnuplot> pr s.i
a1
So, only value("a".i) and value(s.i) works, and value("a".1) and
value(s.1) report errors. Is this a bug?
|
|
From: Ethan A M. <sf...@us...> - 2011-11-23 21:16:15
|
On Tuesday, November 22, 2011 11:22:09 pm gbliu wrote:
> By the way, there seems to be a small bug:
> gnuplot> s="a"
> gnuplot> i=1
> gnuplot> pr "a".1
> ^
> ';' expected
Not really a bug. The command is truly ambiguous because
".1" could be parsed as either the number one tenth or the
string concatenation operator followed by the integer 1.
Notice that
print "A" . 1
works as expected because now there is a space between the
dot and the 1, removing the ambiguity.
Ethan
> gnuplot> pr "a".i
> a1
> gnuplot> pr s.1
> ^
> ';' expected
> gnuplot> pr s.i
> a1
>
> So, only value("a".i) and value(s.i) works, and value("a".1) and
> value(s.1) report errors. Is this a bug?
>
>
>
>
>
|