I typically use GLE to make a grid of plots, say 3x3 plots on a page with 5 lines per plot. All plots use the same X values, in column 1 of the data file, and the remaining 3x3x5 columns contain the data for the 3x3x5 lines. I seek ways of making the 9 graphs more efficiently. Perhaps the most annoying task is to change the columns for the 9 graphs, which might look like this across successive graphs:
data datafile.dat d1=c1,c2 d2=c1,c3 d3=c1,c4 d4=c1,c5 d5=c1,c6
data datafile.dat d1=c1,c7 d2=c1,c8 d3=c1,c9 d4=c1,c10 d5=c1,c11
data datafile.dat d1=c1,c12 d2=c1,c13 d3=c1,c14 d4=c1,c15 d5=c1,c16
etc
It would be nice if I could tell GLE to ignore cols 2-6 when reading the data for the second graph, ignore 2-11 when reading the data for the third graph, etc, so that the data could be referred to in the same way for all graphs. Or maybe there is an easier way that I have missed. Do you have any ideas for me? See the attached for an example GLE file that illustrates the problem, with lots of tiny changes from one graph to the next. Thanks.
Example GLE file illustrating the problem
Dear Jeff,
To draw many similar graphs on a page, it's best to define a subroutine to draw one graph and then call that subroutine multiple times. Below is an example of how you could use this approach to solve your problem.
One important function to know to accomplish this is \expr{...}. This can be used in graph blocks, and its argument is substituted at that position in the block before the block is executed. I use this in the example below to define the columns that are to be used from the dataset.
For example:
size 15 15
x0 = 0; y0 = 0
fx = 5; fy = 5
xp = 0; yp = 0
sub drawgraph title$ dataset
local ds0 = (dataset-1)*5+2
amove xp*fx+x0 pageheight()-(yp+1)*fy+y0
begin graph
size 5 5
title title$
xaxis min 0 max 5 dticks 1
yaxis min 0 max 5 dticks 1
data "Example3x3x5.csv" d1=c1,c\expr{ds0} d2=c1,c\expr{ds0+1} d3=c1,c\expr{ds0+2} d4=c1,c\expr{ds0+3} d5=c1,c\expr{ds0+4}
d1 lstyle 1
d2 lstyle 2
d3 lstyle 3
d4 lstyle 4
d5 lstyle 5
end graph
xp = xp + 1
if xp > 2 then
xp = 0; yp = yp + 1
end if
end sub
for i = 1 to 9
drawgraph "Title "+num$(i) i
next i
Can you give this script a try?
Let me know if this helps or if you have any further questions.
Best Wishes,
Jan.
Thanks, jeans, I had no idea that I could define a graph as a subroutine. This will be extremely useful to me! One small remaining point: I usually just put the key in one of the many graphs. I can cluge this right now by using \expr{keytype$} within the subroutine, and defining keytype$ as either a normal "key pos tl" when I want a key or as "key offset 1000 1000" when I don't want the key (i.e., move it off the page). This seems pretty inelegant--can you suggest a better way to turn keys on and off? Thanks again...Jeff
Dear Jeff,
I'll add an "off" option to the "key" command of the graph block (or a Boolean option "enable"). This seems like a useful feature.
Currently, there are three ways to disable the key in some of the graphs:
(1) Define the key as a separate key block (with "begin key"/"end key") and put this in an if-then block. E.g.,
if showkey = 1 then
begin key
line color red text "Method 1"
line color blue text "Method 2"
end key
end if
this method has the disadvantage that you have to copy the line colors and marker types from the "dn" lines in the graph block, which may be error prone.
(2) Include a header in your data files, i.e., the key entries are in the first row of your data file. E.g.,
"X", "Method 1", "Method 2"
1, 0, , 1
2, 1.5, , 3
...
now, GLE will automatically take the key from this first line of your data file. Then use this as graph block:
if showkey = 1 then
ignore$ = ""
else
ignore$ = "ignore 1"
end if
begin graph
key pos tl
data "myfile.csv" \expr{ignore$}
d1 line color red
d2 line color blue
end graph
if now showkey <> 1, then the option "ignore 1" will be included in the loading of the dataset and the first row will be ignored. As a result no key is shown.
Maybe this solution is a bit far fetched, but it should work.
(3) Conditionally add the "key" options to the "dn" commands. E.g.,
sub optional_key(txt$)
if showkey = 1 then
return "key "+txt$
else
return ""
end if
end sub
begin graph
key pos tl
data "myfile.csv"
d1 line color red \expr{optional_key("Method 1")}
d2 line color blue \expr{optional_key("Method 2")}
end graph
I hope this helps.
Best Wishes,
Jan.
I've implemented the "key off" functionality in GLE 4.2.2-S070909, which is available from the CVS page:
<http://www.gle-graphics.org/cvs.html>
Best,
Jan.