2
votes

I have a data file, the data for y axis are in the third column. I would like to have the scale given by the first column on the x1 and by the second column on the x2. The standard way would be to:

plot data u 1:2 axes x1y1, data u 1:3 x2y1

But that creates two plots which is something I want to avoid. Of course one could make the above work with colours or with some other dirty tricks. It makes the whole plot code very cumbersome. Another nice way is to use multiplot as suggested here. But this is not really my goal, as I want to have the the real x2 axis.

Another way that came to my mind was to set x2range but that means going to the source file and figuring out the min and max or using some statistics in gnuplot (which feels like a waste of time for such a simple thing).

Is there any more simple and elegant way than the above ones? (I am especially concerned about the solution to be short to write, the plot can consist of several (>5) datasets and doing and I want to avoid plotting each dataset twice.

1
Could you provide some data, and an illustration of the plot you would like to achieve? I am confused by your sample plot command -- it never relates the second column to the x2 axis. Why do you not want two plots? If you are just looking for a static, data-independent relationship between the x and x2 axis, you can use set link. - user8153

1 Answers

1
votes

This can be done in this way, by telling gnuplot to re-scan file with 2nd column as x2 values but only invalid y-values for this second plot:

set xtics nomirror
set xrange [:] noextend
set x2tics
set x2range [:] noextend
plot '/tmp/f.gdat' u 1:3 w l, '' u 2:(1/0) ax x2y1

As an example, you can plot this data with Celsius on x and Fahrenheit on x2:

0       32      0
30      86      1
60      140     2
90      194     3

Note that this will only be sensible if column 2 is affinely linked with column 1. If you know the affine relation, using set link is much better.