I am plotting several datafiles within the same frame using the multiplot
command in gnuplot (version 5.2
). I was able to reproduce the issue I am facing with this code below where for instance instead of datafiles I am plotting simple sin
-functions.
Code
reset session
# ****** margins *****
if (!exists("MP_LEFT")) MP_LEFT = 0.1
if (!exists("MP_RIGHT")) MP_RIGHT = 0.95
if (!exists("MP_BOTTOM")) MP_BOTTOM = 0.075
if (!exists("MP_TOP")) MP_TOP = 0.925
if (!exists("MP_GAP")) MP_GAP = 0.025
# ****** Macros *****
XLABEL = "set xlabel '{/:Italic=20 x}' offset graph 0, 0.3"
NOXLABEL = "unset xlabel"
NOXTICS = "set format x ''"
NOYTICS = "set format y ''"
OBJECT = "unset object; set object circle at graph 0, 0 radius scr 0.1"
set terminal pngcairo
set termoption font "Times, 12"
set output "test.png"
set multiplot layout 2, 2 rowsfirst \
margins scr MP_LEFT, MP_RIGHT, MP_BOTTOM, MP_TOP \
spacing scr MP_GAP
@NOXLABEL
@XLABEL
@NOXTICS
@NOYTICS
@OBJECT
plot sin(x) w l title "sin(x)"
@NOXLABEL
@XLABEL
@NOXTICS
@NOYTICS
plot sin(x + pi/4) w l title "sin(x + {/Symbol p}/4)"
@NOXLABEL
@XLABEL
@OBJECT
@NOXTICS
@NOYTICS
plot sin(x + pi/2) w l title "sin(x + {/Symbol p}/2)"
@NOXLABEL
@XLABEL
@OBJECT
@NOXTICS
@NOYTICS
plot sin(x + pi) w l title "sin(x + {/Symbol p})"
unset multiplot
unset output
Macros are very useful in multiplot as it helps to share similar commands across all the subplots as I am doing for instance with the macro OBJECT
. However, here I failed to understand why the offset I am chosing for the xlabels using the macro XLABEL
creates different shifts with respect to the xaxis
on the different subplots, especially the ones in (line:1, col:1) and (line:2, col:1) in the result below.
Result
Can anyone help fix the misbehavior of the xlabel in the macro? An explanation of the issue is welcome.
You can fix the behaviour if you use e.g. offset screen 0,0.15
or offset 0,4
instead of offset graph 0.3
.
This might fix the issue but does not explain the unexpected behaviour with offset graph
. A bug? At least something with origins and sizes of sub-plots in a multiplot environment. But this has nothing to do with the macro itself. Check the following further minimized examples.
Code 1:
reset session
set multiplot layout 2,2 rowsfirst
set xlabel "x label" offset graph 0, 0.3
plot x
plot x
plot x
plot x
unset multiplot
Result 1:
Code 2:
reset session
set multiplot layout 2,2 rowsfirst
set xlabel "x label" offset screen 0, 0.15
plot x
plot x
plot x
plot x
unset multiplot
Result 2: