Reputation: 545
I am having trouble using a for loop in gnuplot inside the plot command. Here is a pared down gnuplot script, which focuses on the parts that aren't working:
set multiplot layout 1, 3 title "Convergence Plots"
planeIter=4
do for [ringIter=0:20:10] {
if (ringIter == 0) {ringName="outer"} else {if (ringIter == 10) {ringName="middle"} else {ringName="inner"}}
set title "Pressure in ".ringName." ring"
plot for [quadIter=0:90:30] path1 every ::5 using 1:(1 + planeIter + ringIter + quadIter) notitle # title quadName.' quadrant' with lines
# if (quadIter == 0) {quadName="first"} else {if (quadIter == 30) {quadName="second"} else {if (quadIter == 60) {quadName="third"} else {quadName="fourth"}}}
}
My questions are:
I have included an image of what it looks like and what it should look like (below), which I have generated by not using for loops and variables for quadName.
The file, p, is a list of numbers, each row containing 121 columns.
Thank you for any help you can provide.
Upvotes: 1
Views: 1812
Reputation: 48390
To use a variable to specify the selected column, you must use column(var)
, i.e. in your case it would be using 1:(column(1 + planeIter + ringIter + quadIter))
.
To select a word for the title, you can define a function which returns the respective string, like:
quadName(x) = (x == 0 ? "first" : (x == 30 ? "second" : (x == 60 ? "third" : "fourth")))
plot for [quadIter=0:90:30] path1 using 1:(column(1 + planeIter + ringIter + quadIter)) \
title quadName(quadIter).' quadrant' with lines
Alternatively you could also use the word
function, which might be nicer for more selections:
quadName = "first second third fourth"
plot for [quadIter=0:90:30] path1 using 1:(column(1 + planeIter + ringIter + quadIter)) \
title word(quadName, (quadIter / 30) + 1)
Upvotes: 1