Search code examples
gnuplotmultiple-axes

Multiple y axis sections in a multiplot


I'v got a multiplot 2,2 with 5 lines in each plot, the lines range around the same values from 600-700 on the y value so they're overlapping. I added +60 +120 +180 and +240 to the y values and it would do the trick but isn't there a way in gnuplot to add multiple sections on the y axes. So I'd plot the first line in the first section, second in the second and so on and each section ranges from 600-700 one of the 4 plots in the multiplot looks like this: enter image description here

My Code:

set multiplot layout 2,2 title "Spring Summer Fall Winter"
set title 'Spring'
plot 'Data1.csv' every ::614::637 using 2:3 w l title 'CI 0.2',\
"" every ::963::964 using 2:($3+20) w l title 'CI 0.4 [{/Symbol l}ave+20]',\
"" every ::1080::1084 using 2:($3+40) w l title 'CI 0.6 [{/Symbol l}ave+40]',
set title 'Sommer'
plot 'Data2.csv' every ::1074::1155 using 2:3 w l title 'CI 0.2',\
"" every ::2548::2618 using 2:($3+60) w l title 'CI 0.4 [{/Symbol l}ave+60]',\
"" every ::4017::4092 using 2:($3+120) w l title 'CI 0.6 [{/Symbol     l}ave+120]',\
"" every ::5580::5655 using 2:($3+180) w l title 'CI 0.8 [{/Symbol l}ave+180]',\
"" every ::7186::7280 using 2:($3+240) w l title 'CI 1.0 [{/Symbol l}ave+240]',
set title 'Fall'
plot 'Data3.csv' every ::43::43 using 2:3 w l title 'CI 0.2',\
"" every ::63::63 using 2:($3+20) w l title 'CI 0.4 [{/Symbol l}ave+20]',\
"" every ::87::87 using 2:($3+40) w l title 'CI 0.6 [{/Symbol l}ave+40]',\
"" every ::135::139 using 2:($3+60) w l title 'CI 0.8 [{/Symbol l}ave+60]',\
"" every ::311::362 using 2:($3+80) w l title 'CI 1.0 [{/Symbol l}ave+80]',
set title 'Winter' 
plot 'Data4.csv' using 2:3 every ::788::829 w l title 'CI 0.2',\
"" every ::1256::1268 using 2:($3+20) w l title 'CI 0.4 [{/Symbol l}ave+20]',\
"" every ::1512::1525 using 2:($3+40) w l title 'CI 0.6 [{/Symbol l}ave+40]',\
"" every ::1681::1686 using 2:($3+60) w l title 'CI 0.8 [{/Symbol l}ave+60]',
unset multiplot
unset output

So what I've already got is a Multiplot with one plot for each season: In every Plot there are up to 5 lines showing some data. Most of the data on the y axes is in an area between 600 and 700 so in order to avoid overlapping lines which are hard to distinguish even with different colors I plotted the first line normally, and then all the other lines with some additional point (+40 +60and so on) so that all the lines are not on the same spot in the plot but on top of each other, so you can compare tendencies and drifts.

What I want to know is if theres a way to simply cut the y axes into up to 5areas each reaching from 600-700so I can plot one line in the top area (600-700) the next one in the are below the one before and so on. So all lines are in the same value field but on top of each other so you can distinguish between them easier but and don't have to mind the +20 or whatever value when looking ad the y axes, since each of those areas on the y axes could have tics and a grid. Here's an image I made ... enter image description here


Solution

  • Proof of concept rather than a a complete solution but I think you can use this and start customizing from here:

    set multiplot layout 6, 2
    
    set format x ""      # no xtic labels
    set ytics -4, 2, 4   # adequately spaced, non-overlapping ytic labels
    
    set bmargin 0
    plot[][-5:5] "so.dat" every ::0::4 w lp t "spring 1"
    plot[][-5:5] "so.dat" every ::5::9 w lp t "summer 1"
    
    set tmargin 0
    plot[][-5:5] "so.dat" every ::10::14 w lp t "spring 2"
    plot[][-5:5] "so.dat" every ::0::4 w lp t "summer 2"
    
    set bmargin 1
    plot[][-5:5] "so.dat" every ::15::19 w lp t "spring 3"
    plot[][-5:5] "so.dat" every ::10::14 w lp t "summer 3"
    set tmargin 1
    
    set bmargin 0
    plot[][-5:5] "so.dat" every ::0::4 w lp t "fall 1"
    plot[][-5:5] "so.dat" every ::5::9 w lp t "winter 1"
    
    set tmargin 0
    plot[][-5:5] "so.dat" every ::10::14 w lp t "fall 2"
    plot[][-5:5] "so.dat" every ::20::24 w lp t "winter 2"
    
    set bmargin 1
    plot[][-5:5] "so.dat" every ::5::9 w lp t "fall 3"
    plot[][-5:5] "so.dat" every ::10::14 w lp t "winter 3"
    
    unset multiplot
    

    Resulting graph:

    enter image description here

    Data file so.dat:

    1   -1.8351
    2   0.6315
    3   -1.3365
    4   2.1251
    5   -0.6708
    6   -3.3965
    7   -0.2298
    8   0.4807
    9   -2.4213
    10  -0.5998
    11  -1.0238
    12  -0.2025
    13  0.4362
    14  -1.1263
    15  3.3197
    16  0.0337
    17  -0.7374
    18  1.1504
    19  -0.1656
    20  -0.4389
    21  1.4645
    22  1.6538
    23  1.6362
    24  -2.0363
    25  -4.9741