plotgnuplotyaxisadjustment

How to produce dependable dual y-axis?


I have this dataset:

x-axis y-axis y2-axis
15 9.585 88.38
45 9.4185 86.85
60 9.2655 85.44

I want to produce plot that two different y-axis in gnuplot, which is dependable each other
But, I troubled to adjust the second y-axis to the first one image As you can see from the graph and dataset, the value of each points didn't exactly same from the dataset, it's just like the y2-axis just plotted there, without even adjusted to the values in dataset.
Is it possible to produce such graph?

Here's my code I worked before:

set xrange [5:70]
set yrange [9.1:9.7]
set y2range [85:89]
unset key

set xtics 15 font ",18" nomirror
set xlabel "x-axis" font ",24"
set xlabel offset 0,-.5
set ytics .2 font ",18" nomirror 
set ylabel "y-axis" font ",24"
set ylabel offset -1.5
set y2tics font ",18" 
set y2label "y2-axis" font ",24"

plot "Dataset.txt" with linespoints ls 1

Solution

  • Please check help link. You can define a function (and the inverse of it) if you want to link axes.

    Syntax:

      set link {x2 | y2} {via <expression1> inverse <expression2>}
      unset link
    

    The set link command establishes a mapping between the x and x2 axes, or the y and y2 axes. maps primary axis coordinates onto the secondary axis. maps secondary axis coordinates onto the primary axis.

    From your numbers I guess that the relation between your y1-axis and y2-axis is simply a factor of 9.221.

    Script:

    ### linked y-axes
    reset session
    
    $Data <<EOD
    x-axis  y-axis  y2-axis
    15      9.585   88.38
    45      9.4185  86.85
    60      9.2655  85.44
    EOD
    
    c = 9.221
    
    set xlabel "x axis"
    set xrange [5:70]
    
    set ylabel "y1 axis"
    set ytics 0.1 nomirror
    
    set link y2 via y*c inverse y/c
    set y2label "y2 axis"
    set y2tics 0.5
    
    plot $Data u 1:2 w lp pt 7 lc "red"
    ### end of script
    

    Result:

    enter image description here