Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.graphics.apps.gnuplot > #3667

Re: Using arrays

Path csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From John Edwards <johned0@gmail.com>
Newsgroups comp.graphics.apps.gnuplot
Subject Re: Using arrays
Date Sun, 4 Jun 2017 09:30:14 +0100
Lines 105
Message-ID <ephuoqF8oahU1@mid.individual.net> (permalink)
References <epgtapF1peqU1@mid.individual.net> <oh08o7$90q$1@dont-email.me>
Reply-To johned0@gmail.com
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net djpOeIJ4lP+U0vlqxgUcLgu6oHcChcoywEVi3ZzDKlBs6agpMy
Cancel-Lock sha1:rb8KgjwsSM0cT90SeqYx5FoAmDk=
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1
In-Reply-To <oh08o7$90q$1@dont-email.me>
Content-Language en-GB
Xref csiph.com comp.graphics.apps.gnuplot:3667

Show key headers only | View raw


On 04/06/2017 07:22, Ethan A Merritt wrote:
> 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.migh
> 
> 	cheers,
> 
> 		Ethan
> 
> 
Hi Ethan,
Thank you very much for your fast response.
I'll be honest, I made the assumption that gnuplot would just treat the 
elements as columns that could represent any format of data, not just 
complex.
I think your named datablock suggestion might fit my requirements.
Thanks again.
John

Back to comp.graphics.apps.gnuplot | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Using arrays John Edwards <johned0@gmail.com> - 2017-06-03 23:59 +0100
  Re: Using arrays Ethan A Merritt <EAMerritt@gmail.com> - 2017-06-03 23:22 -0700
    Re: Using arrays John Edwards <johned0@gmail.com> - 2017-06-04 09:30 +0100
    Re: Using arrays Ethan A Merritt <sfeam@users.sourceforge.net> - 2017-06-05 09:41 -0700

csiph-web