Search code examples
gnuplot

In GNUPLOT mutliplot option, the label for X-axis is not plotted for second plot


I have two plots in multiplot, on my second plot ticks label is not appearing, which I want to appear at the bottom X-axis

#!/usr/bin/gnuplot
reset
set border lw 30
set term pngcairo size 10000,10000 font "arial-Bold,130"
set output 'out.png'
set multiplot layout 2,2
unset key

set size ratio 1.2
set style data lines
set xtics format ""
set x2tics nomirror
set ytics out nomirror
set ytics 0,20 
set x2label "Vs (km/s)" offset -1.0
set ylabel 'Depth (km)' offset 1.5
set xrange [0:5]
set yrange [200:0]
set label 3 at 2,120
set key samplen 1.7 at 3.0,135
#
set label 1 '(a)' font "arial-Bold,130" at 0.8,15 right 
set label 3 "C3 (MNAI)" center font "arial-Bold,130"


plot     'MAN.inmd' lc rgb 'blue'   lw 35 title "Initial  model"     with fsteps,\
'MAN.outmd' lc rgb 'red' lw 35  dt"-" title "Inverted model" with fsteps ,
unset x2label
unset x2tics
unset ylabel
unset ytics

#
set size ratio 0.9
set xlabel 
set xtics 5
set ytics 0.5 
set xlabel "Period (s)" offset 2.5
set ylabel "Group Velocity (km/s)" offset 2.5
set xrange [15:45]
set yrange [3:4.5]
set label 3 at 30,3.5
set label 4 at 18,4.3
set label 5 at 20,4.0 font "arial-Bold,130"


set key right bottom samplen 0.9
#
set label 3 "C1 (MNAI)" center font "arial-Bold,130"
set label 5 "Rayleigh wave dispersion curves" font "arial-Bold,130"
set label 4 "(a)" center font "arial-Bold,97"
plot  'MANdsp.out' lc rgb 'red'   lw 35 title "Model fit dispersion curve",\
'mandsp.in' lc rgb 'blue' lw 35  dt"-" title "Observed dispersion curve" smooth acsplines,




 unset multiplot

The ticks are appearing on X-axis, but the ticks X-axis bottom labels are not appearing. I have tried other ways too, but unable to come over it


Solution

  • Regarding xtics, you do the following:

    ...
    set xtics format ""         # Don't print x-axis bottom tic labels!!!
    ...
    set x2tics nomirror         # Print x2tics, tic labels are included by default.
    ...
    ...# First plot             # -> You see x2 tic labels.
    ...
    unset x2tics                # Don't print x2 tics
    ...
    set xtics 5                 # Print x-axis tics, but keep empty tic labels.
    ...
    ...# Second plot            # -> no x2 tics; xtics are printed without labels.
    

    You can reset the x-axis tic label default format with:

    set xtics 5 format "% h"
    

    See help set format for other format options.


    So if I take your script and change it with the following steps

    • replace the two plot commands with plot sin(x), cos(x) because you did not show the data,
    • replace the set xtics 5 command by set xtics 5 format "% h",

    I arrive at this script:

    #!/usr/bin/gnuplot
    reset
    set border lw 30
    set term pngcairo size 10000,10000 font "arial-Bold,130"
    set output 'out.png'
    set multiplot layout 2,2
    unset key
    
    set size ratio 1.2
    set style data lines
    set xtics format ""
    set x2tics nomirror
    set ytics out nomirror
    set ytics 0,20 
    set x2label "Vs (km/s)" offset -1.0
    set ylabel 'Depth (km)' offset 1.5
    set xrange [0:5]
    set yrange [200:0]
    set label 3 at 2,120
    set key samplen 1.7 at 3.0,135
    #
    set label 1 '(a)' font "arial-Bold,130" at 0.8,15 right 
    set label 3 "C3 (MNAI)" center font "arial-Bold,130"
    
    
    #plot     'MAN.inmd' lc rgb 'blue'   lw 35 title "Initial  model"     with fsteps,\
    #'MAN.outmd' lc rgb 'red' lw 35  dt"-" title "Inverted model" with fsteps ,
    plot sin(x), cos(x)
    
    unset x2label
    unset x2tics
    unset ylabel
    unset ytics
    
    #
    set size ratio 0.9
    set xlabel 
    set xtics 5 format "% h"
    set ytics 0.5 
    set xlabel "Period (s)" offset 2.5
    set ylabel "Group Velocity (km/s)" offset 2.5
    set xrange [15:45]
    set yrange [3:4.5]
    set label 3 at 30,3.5
    set label 4 at 18,4.3
    set label 5 at 20,4.0 font "arial-Bold,130"
    
    
    set key right bottom samplen 0.9
    #
    set label 3 "C1 (MNAI)" center font "arial-Bold,130"
    set label 5 "Rayleigh wave dispersion curves" font "arial-Bold,130"
    set label 4 "(a)" center font "arial-Bold,97"
    
    #plot  'MANdsp.out' lc rgb 'red'   lw 35 title "Model fit dispersion curve",\
    #'mandsp.in' lc rgb 'blue' lw 35  dt"-" title "Observed dispersion curve" smooth acsplines,
    plot sin(x), cos(x)
    
    unset multiplot
    

    And I get this picture with x axis tic labels on the right diagram:

    with bottom x axis tic labels on the right diagram