How to realize a single plot in a double loop?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to realize a single plot in a double loop?

theozh
Hello,
I am trying to plot with a "double loop" into one single plot.

For example something like:
plot for [i=1:5][j=1:5] sin(i*j*x) w l

But a 2D loop apparently does not exist in gnuplot?!

First trial:
set label 1 "This is a double loop"
do for [i=1:5] {
  plot for [j=1:5] sin(i*j*x)
}

This basically works, however, the axis and labels are printed several
times on top of each other such that the output (axis and labels) look
blurry or pixelated.

Second trial:
Same thing if I use multiplot.

set multiplot layout 1,1
do for [i=1:5] {
  plot for [j=1:5] sin(i*j*x)
  set multiplot previous
}
unset multiplot

Third trial:
Unsetting border, label, tics, ... after the first plot
unset border
unset label
unset xtics
However, this changes the following plot sizes...

Any ideas how to circumvent that several identical axis and labels are
plotted on top of each other and start looking blurry/pixelated?

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
gnuplot-info mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to realize a single plot in a double loop?

thse
multiple for-loops are possible:

gnuplot> help for
...
...
 Nested iteration is supported:

       set for [i=1:9] for [j=1:9] label i*10+j sprintf("%d",i*10+j) at i,j
...

i.e.,
plot for [i=1:5] for [j=1:5] sin(i*j*x)
will work.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to realize a single plot in a double loop?

theozh
Thank you! You're right.
Well, if you check help starting with "plot" I see a link to subtopics
"for loops in plot command". But there, nested iteration is not
mentioned. Might be helpful there to set a link to "for". Unfortunately,
I haven't checked help for "for".

However, I just noticed that in order to illustrate my problem I
simplified it too much. This nested loop will actually not (yet) solve
my problem.

Let me try to explain:

I have datafiles which are named with the following scheme:
Data_<1>_<2>_<3>
<1> is a known, limited range e.g. A,B,C,D,E,F,G,H,I
<2> is a unknown, variable range, e.g. a,b,c,d,...
<3> is a unknown, variable range, e.g. 1,2,...

What I would like to plot is in a Multiplot:
All Data_A in the first plot, Data_B in the second, etc...
where a,b,c,... determines the color of the line
and 1,2,... are just data from repeated measurements.

The difficulty is that not files for all combinations, e.g. A_a_1, ...
I_d_9 might exist.
I get the existing filenames via one or several system calls, e.g.
FileList = system("dir /B /S Data_A_*.dat")
or
FileList = system("dir /B /S Data_A_a_*.dat")

I currently do not see how to loop this for each plot of the multiplot.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
gnuplot-info mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to realize a single plot in a double loop?

theozh
ok... maybe I simply loop all the files
"Data_<Index1>_<Index2>_<Index3>.dat"
with respect to the first two indices and put them all in one list per
plot. Additionally, in parallel I need to create a color list which
corresponds to <Index2>.
With this gnuplot checks [A...I] (9) x [a...f] (6) =54 times whether are
files existing. Not very elegant, but seems feasible...

Regular expressions in gnuplot might be nice e.g. to create sublists or
define the color from the filenames...

### gnuplot code
Index1 = [A B C D E F G H I]
Index2 = [a b c d e f]
ColorList = ""
AllFileList = ""

set multiplot layout 3,3
do for [iii = 1:words(Index1)] {
  do for [jjj = 1:words(Index2)] {
    FileList = system('dir /B /S Data_'.Index1.'_'.Index2.'_'*.dat')
    do for [kkk = 1:words(FileList)] { ColorList = ColorList." ".jjj }
    AllFileList = AllFileList." ".FileList
  }
  plot for [mmm = 1:words(AllFiles)] word(AllFiles,mmm) u 1:2 w l lc
word(ColorList,mmm) notitle
}
unset multiplot
### end gnuplot code
### Still needs to be tested when several files are not existing.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
gnuplot-info mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to realize a single plot in a double loop?

Dave Horsfall
In reply to this post by thse
On Wed, 2 Aug 2017, thse wrote:

> multiple for-loops are possible:
>
> gnuplot> help for
> ...
> ...
> Nested iteration is supported:
>
>       set for [i=1:9] for [j=1:9] label i*10+j sprintf("%d",i*10+j) at i,j
> ...
>
> i.e.,
> plot for [i=1:5] for [j=1:5] sin(i*j*x)
> will work.

Well, if I could print that out in A0 it would make a surreal picture on
my wall...

--
Dave Horsfall DTM (VK2KFU)  "Those who don't understand security will suffer."

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
gnuplot-info mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to realize a single plot in a double loop?

Gnuplot - User mailing list
In reply to this post by theozh
On Wednesday, 02 August 2017 16:46:27 theozh wrote:

> ok... maybe I simply loop all the files
> "Data_<Index1>_<Index2>_<Index3>.dat"
> with respect to the first two indices and put them all in one list per
> plot. Additionally, in parallel I need to create a color list which
> corresponds to <Index2>.
> With this gnuplot checks [A...I] (9) x [a...f] (6) =54 times whether are
> files existing. Not very elegant, but seems feasible...
>
> Regular expressions in gnuplot might be nice e.g. to create sublists or
> define the color from the filenames...
>
> ### gnuplot code
> Index1 = [A B C D E F G H I]
> Index2 = [a b c d e f]
> ColorList = ""
> AllFileList = ""
>
> set multiplot layout 3,3
> do for [iii = 1:words(Index1)] {
>   do for [jjj = 1:words(Index2)] {
>     FileList = system('dir /B /S Data_'.Index1.'_'.Index2.'_'*.dat')
>     do for [kkk = 1:words(FileList)] { ColorList = ColorList." ".jjj }
>     AllFileList = AllFileList." ".FileList
>   }

You are either inventing syntax that doesn't exist or mangling syntax
that does exist.  I think your intent is something like

array index1 = ["A", "B", "C", "D", "E", "F", "G", "H", "I"]
file(i,j) = sprintf("%s_%d.dat", index1[i], j)

do for [iii = 1:|index1|] for [jjj = 1:*] {
    plot file(i,j) with ... lc variable
}

I left out the color because it wasn't clear to me where it comes from,
but it sounds like you want to use it as a variable to color the lines
rather than as an element to loop over.   So that would be something
involving "lc variable"

> unset multiplot
> ### end gnuplot code
> ### Still needs to be tested when several files are not existing.

missing files should not be a problem except that the iteration
[jjj = 1:*] will terminate at the first missing file. So if there are gaps
in the numbering you must give an explicit upper bound rather than *.
See for instance the second plot in
        http://gnuplot.sourceforge.net/demo_cvs/iterate.html

At least that's the intent.  If you find otherwise please report it as a bug.

        Ethan

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
gnuplot-info mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info
Loading...