Re: PlottingArrays

Geoff Kaniuk <[email protected]> Fri, 16 Sep 2022 13:21:16 +0100
Newsgroups gmane.comp.graphics.gnuplot.user
Message-ID <[email protected]>
Thank you all for the swift replies. This made me realise that my 
looped plot example produces separate plots for each array, but I wanted 
all curves in 1 plot.

Using the eval clue I have come up with a solution looking like this:

STEP1. create a function curves(n)
	to generate the string  "ab1 w lp, ab2 w lp"
	( I wonder if this what Alan Corey meant by search & replace)

STEP2.
	curves = curves(2)
	plotcurves = "plot ".curves
	eval(plotcurves)

Using sprintf to get plotcurves also worked. One slight issue is that I 
had missed a space after the comma separating the plot elements. So  the 
generated string  "ab1 w lp,ab2 w lp" failed, with plot trying to treat 
it as the name of a single file. However plot ab1 w lp,ab2 w lp is fine.
	
Although this is a solution for a handful of arrays, is this really the 
only way?

Geoff
33 Ashbury Close, Cambridge CB1 3RW 01223 710582

On 15/09/2022 21:37, Ethan Merritt wrote:
> On Thursday, 15 September 2022 11:06:44 PDT Geoff Kaniuk wrote:
>> Dear gnuplot,
>>
>> I would like to plot a sequence of arrays.
>>
>> For example, I have a script:
>>
>> plot-arrays.gp
>> # TEST PLOT ARRAYS
>> reset session
>>
>> array ab1[3] = [ 1.1, 1.2, 1.3 ]
>> array ab2[3] = [ 2.1, 2.2, 2.3 ]
>>
>> plot ab1 w lp, ab2 w lp
>>
>> abname(i)=sprintf("%s%d", "ab", i)
>>
>> do for [k=1:2]{ abk = abname(k); plot abk w lp }
>> # END
>>
>> The first plot command works fine. But I have a large number of such
>> arrays and would like to proceed as in the second looped command.
> 
> See "help eval".
> You want something like this
> 
>    do for [k=1:N] {
>      command = sprintf("plot ab%d w lp", k)
>      eval(command);
>    }
> 
> 	Ethan
> 
> 
> 


_______________________________________________
gnuplot-info mailing list
[email protected]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info