Search code examples
plotgnuplot

Gnuplot multiplot with 2 plots stacked over each other


I am having trouble getting a multiplot with gnuplot where two plots are stacked over each other. I came this far with the following code:

multiplot> unset xtics
multiplot> set xrange [:108]
multiplot> plot "haildays_north_south.txt" u 0:4 w line lc rgb "blue" t "POH timeseries north", f(x) w line lc rgb "red" t "f(x) = -0.012x+5.27"
multiplot> set xtics ("2002" 1, "2004" 13, "2006" 25, "2008" 37, "2010" 49, "2012" 61, "2014" 73, "2016" 85, "2018" 97, "2020" 108)
multiplot> set xrange [:108]
multiplot> set yrange [:16]
multiplot> set ylab "Number of haildays per month"
multiplot> set xlab "Months (April-September 2002-2019)"
multiplot> plot "haildays_north_south.txt" u 0:3 w line lc rgb "blue" t "POH timeseries south", g(x) w line lc rgb "red" t "f(x) = 0.026x+2.87"

enter image description here

However, I would like the upper plot to have the vertical grid lines too, I need the whole plot as a size .7,.7 and I only want one ylabel centered between both plots if possible. Unfortunately I don´t know in which order I need to call the commands and which exactly.

Help would be gladly appreciated! Best , Lena


Solution

  • Adding vertical grid lines can be done using the same command as you used already but give blank labels. You may want to suppress the tic marks also:

    set xtics scale 0.0
    set xtics ("" 1, "" 13, "" 25, "" 37, "" 49, "" 61, "" 73, "" 85, "" 97, "" 108)
    

    I am not sure I understand the question about placing a y label between the plots. Did you really mean the x label (i.e. only one copy rather than one under each plot)? For that you can add unset xlabel before the second plot command, and adjust the vertical positioning of the remaining label using the offset keyword.

    If you really do mean the ylabel, the same method applies.

    Revised script:

    set xrange [:108]
    set xtics scale 0.0
    set xtics ("" 1, "" 13, "" 25, "" 37, "" 49, "" 61, "" 73, "" 85, "" 97, "" 108)
    set xlabel "Months (April-September 2002-2019)" offset 0,-1
    plot "haildays_north_south.txt" u 0:4 w line lc rgb "blue" t "POH timeseries north", f(x) w line lc rgb "red" t "f(x) = -0.012x+5.27"
    set xtics ("2002" 1, "2004" 13, "2006" 25, "2008" 37, "2010" 49, "2012" 61, "2014" 73, "2016" 85, "2018" 97, "2020" 108)
    unset xlabel
    set xrange [:108]
    set yrange [:16]
    set ylabel "Number of haildays per month"
    set ylabel left offset 0,10   # left-justified, also shift upwards
    plot "haildays_north_south.txt" u 0:3 w line lc rgb "blue" t "POH timeseries south", g(x) w line lc rgb "red" t "f(x) = 0.026x+2.87"
    

    ~