Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.graphics.apps.gnuplot > #3666
| From | Ethan A Merritt <EAMerritt@gmail.com> |
|---|---|
| Newsgroups | comp.graphics.apps.gnuplot |
| Subject | Re: Using arrays |
| Date | 2017-06-03 23:22 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <oh08o7$90q$1@dont-email.me> (permalink) |
| References | <epgtapF1peqU1@mid.individual.net> |
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
Back to comp.graphics.apps.gnuplot | Previous | Next — Previous in thread | Next in thread | Find similar
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