Search code examples
gnuplotyaxis

Why do I have a problem with the two axes on the right when I use the multi-axis function?


I am having a series of problems when defining the axes in my graphic and I would like to share it with you to see if among all we can find the error

I have found on this website a user who has made it similar. My idea is to have one axis on the left and two on the right. But for some reason, it's probably silly, it does not appear correctly.

My code is as following:

set terminal postscript eps enhanced color "Times-Roman" 15
set output "TC_8.eps"
set multiplot
set xlabel "Temperature/{/Symbol \260} C"
set xrange [0:1500]
set key off
set autoscale  y
set autoscale y2


##### first plot


set yrange[0:15]
set ylabel "Thermal Diffusivity/(mm^2/s)" textcolor rgb "red"
plot "dt8.txt" using 1:2 smooth cspline lc rgbcolor "red"


##### Second plot

set y2range[0:40]
set y2tics nomirror
set y2label "Thermal Conductivity/ (W/m K))" offset 8, 0 textcolor rgb "green"

plot "dt8.txt" using 1:4 axes x1y2 smooth cspline lc rgbcolor "green"

##### Third plot

set y2range[0:2]
set y2tics no mirror
set y2label "Specific Heat/ (J/(g K))" offset 16, 0 textcolor rgb "blue"
plot "dt8.txt" using 1:3 axes x1y2 smooth cspline lc rgbcolor "blue"

unset multiplot

and the data series is very simple

20 11.466 0.733 28.894
499.6 6.338 1.119 24.38
998.9 5.3 1.292 23.542
1499 4.639 1.645 26.247

The problem is that the two axes on the right do not appear correctly, and the data lines ... either.

Thanks in advance


Solution

  • Do not hesitate to append your plot result and give the reference where you have found something similar.

    One way might be to change the margins of the graph and plot another dummy graph just for the third (separated) axis. By the way, you can put two datalines into one plot.

    Code: (edit: modified to make it copy&paste including data)

    ### 3 y-axes
    reset session
    
    $Data <<EOD
     20     11.466  0.733  28.894
     499.6   6.338  1.119  24.38
     998.9   5.3    1.292  23.542
    1499     4.639  1.645  26.247
    EOD
    
    set key off
    set autoscale  y
    set autoscale y2
    
    set lmargin 10
    set tmargin 2
    set bmargin 4
    set rmargin 20
    
    set multiplot
    
        ##### first plot
        set xlabel "Temperature / {/Symbol \260}C" font ",11"
        set xrange [0:1500]
    
        set ylabel "Thermal Diffusivity / (mm^2/s)" textcolor rgb "red" font ",11"
        set yrange[0:16]
        set ytics nomirror
    
        set y2range[0:40]
        set y2tics nomirror
        set y2label "Thermal Conductivity / (W/m K)" offset -1,0 textcolor rgb "green" font ",11"
        set grid xtics, ytics
        
        plot $Data u 1:2 axes x1y1 smooth cspline lc rgbcolor "red", \
                '' u 1:4 axes x1y2 smooth cspline lc rgbcolor "green"
    
        ##### Second plot
        unset xlabel 
        unset ylabel
        unset y2label
        unset tics
    
        set y2range[0:2]
        plot $Data u 1:3 axes x1y2 smooth cspline lc rgbcolor "blue" 
    
        ##### Third plot
        set rmargin 10
        set border 8     # only right border visible
        set y2label "Specific Heat/ (J/(g K)" offset -1,0 textcolor rgb "blue" font ",11"
        set y2tics nomirror offset 0,0
        plot NaN    # plot nothing
    
    unset multiplot
    ### end of code
    

    Result:

    enter image description here