1

I'm trying to plot an arbitrary number of lines in a same plot. My data file is like the following:

1  10  15  20
2  20  25  30
3  30  35  40
4  40  45  50
5  50  55  60

I'm using multiplot to do this:

set multiplot
do for [i=1:ny] {
       plot 'data.dat' u 1:i+1 with lines lc i title word(names,i)
}
unset multiplot

where ny=3 in this example. As expected, the yrange of each plot is different, so the graph looks very messy. I'm trying to add

set yrange [ymin:ymax]

where ymin=min(col2,col3,col4,...,coln) is the minimum value among all the columns 2-n and ymax is the maximum value. However, I still don't know how to get ymin and ymax. The function stats allow me to get minimums and maximums for one or two columns at the same time, but no more. Even if I do this column by column, I still don't know how to get the maximum among n scalars.

Any idea?

2 Answers 2

1

You can use if statement, here is the code:

ymin=1000 #set ymin to a very large value
ymax=0    #set ymax to a very small value
do for [i=1:ny] {
stats "data.dat" u i+1
if (STATS_min < ymin) {ymin=STATS_min}
if (STATS_max > ymax) {ymax=STATS_max}
}
Sign up to request clarification or add additional context in comments.

Comments

0

Usually, multiplot isn't for drawing multiple plots in one graph, but to draw several beneath each other. I guess you want to iterate inside the plot command:

plot for [i=1:ny] 'data.dat' u 1:i+1 with lines lc i title word(names, i)

This uses ranges which cover the values of all sub-plots. And it gets the key right.

1 Comment

Thanks! That's what I was actually looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.