Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Ethan A Merritt Newsgroups: comp.graphics.apps.gnuplot Subject: Re: Using arrays Date: Sat, 03 Jun 2017 23:22:16 -0700 Organization: A noiseless patient Spider Lines: 94 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit Injection-Date: Sun, 4 Jun 2017 06:18:47 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="d0cb291210e5cb297c155f81e77a19e5"; logging-data="9242"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Be51Kc8plzSIC4tW5+SNa" User-Agent: KNode/4.14.5 Cancel-Lock: sha1:8FsS2epiTEAfXT1xzUvX5P4mbWs= Xref: csiph.com comp.graphics.apps.gnuplot:3666 John Edwards wrote: > This may be a bit early, since the array functionality was only > released so recently, but I've been trying to use arrays to replicate > the functionality of plotting a multi-column file. > > For example, if I have the following data.dat : > > -90., -1.30e+01 > -60., -3.78e+01 > -30., -1.66e+01 > 0., -5.61e-03 > 30., -1.66e+01 > 60., -3.78e+01 > 90., -1.30e+01 > > And do plot "data.dat" then I get a graph we're all familiar with. > > What I've come up with, to replicate using arrays, is : > > array plt[7] = [ {-90., -1.30e+01}, {-60., -3.78e+01}, {-30., > -1.66e+01}, {0., -5.61e-03}, {30., -1.66e+01}, {60., -3.78e+01}, {90., > -1.30e+01} ] > plot plt u 1:2 > > But it doesn't give me what I expected. > > I would welcome any thoughts. > > Thanks very much, > John Why are you storing complex numbers in the array? Unless you do something fancy, gnuplot only plots the real component of a complex value. So your plot command amounts to plot "data.dat" using 0:1 using the original data format. The second column of numbers is never referenced. If you really want to recover the original data after packing into a set of complex values the plot command would have to be something like plot plt using (real($2)):(imag($2)) That doesn't work either (might be an actual bug lurking there) but at least it tries to unpack the original 2 real values from a single complex value. A variant that does work is plot sample [i=1:7:1] '+' using (real(plt[i])):(imag(plt[i])) That variant is a tour-de-force of new syntax items but I don't see anything gained over using the original data format. Other thoughts that might or might not be relevant to what you want... Using version 5.2 syntax I suppose you could create and plot two parallel arrays: array plt_x[7] = [ 90., -60., -30., 0., 30., 60., 90. ] array plt_y[7] = [-13, -37.8, -16.6, -.00561, -16.6 -37.9, -13. ] plot sample [i=1:7:1] '+' using (plt_x[i]):(plt_y[i]) But why would you want to do this? The more natural representation would be a named data block, not an array. $DATA << EOD -90., -1.30e+01 -60., -3.78e+01 -30., -1.66e+01 0., -5.61e-03 30., -1.66e+01 60., -3.78e+01 90., -1.30e+01 EOD set datafile separator comma plot $DATA using 1:2 Can you explain what you are trying to accomplish by using an array instead of a data block? There are possible additions to the datablock and array syntax that are kicking around as experimental patches because it's not clear that they serve a real need. If you have something in mind that the current syntax can't handle I'd be interested to see if one of these experimental extensions would. cheers, Ethan