在 gnuplot 组多图上设置标签
Set label on group multiplot in gnuplot
我正在使用 gnuplot 用 4 个不同的图形绘制一张图片。它们的 x 轴和 y 轴的标签具有相同的含义。如果我这样画:
set multiplot layout 2,2 rowsfirst
set xlabel "x"
set ylabel "y"
set title offset -3,-3
set xrange [20:70]
set yrange [0:15000]
set title "Plot 1"
plot 'data5.list' u 2:1 w lp pt 7 lt 7 lc rgb 'red' notitle
set xrange [20:70]
set yrange [0:15000]
set title "Plot 2"
plot 'data5.list' u 2:1 w lp pt 7 lt 7 lc rgb 'red' notitle
set xrange [20:70]
set yrange [0:15000]
set title "Plot 3"
plot 'data5.list' u 2:1 w lp pt 7 lt 7 lc rgb 'red' notitle
set xrange [20:70]
set yrange [0:15000]
set title "Plot 4"
plot 'data5.list' u 2:1 w lp pt 7 lt 7 lc rgb 'red' notitle
unset multiplot
我有所有四个图表及其标签,但我想为所有四个图表都添加一个标签,如此 example .
我尝试为其他 3 个图使用未设置的标签,但我只在第一个图上获得标签,而另一个根本没有标签。
您可能希望使用 set label
,而不是使用 xlabel
和 ylabel
。例如,
#!/usr/local/bin/gnuplot
datafile='tmp.dat' # file to plot
set xlabel " " # no x-label
set ylabel " " # no y-label
# assuming all plots have same x and y range
set xrange [-2:2]
set yrange [-4:4]
# same setting for all graph titles
set title offset -3,-3
# puts x-label and y-label manually
set label 1 'x axis' at screen 0.49,0.02
set label 2 'y axis' at screen 0.01,0.5 rotate by 90
# now the graphs: notice that rowsfirst is given by default
set multiplot layout 2,2
do for [i=1:4]{
set title 'plot '.i
plot datafile u 2:1 w lp pt 7 lt 7 lc rgb 'red' notitle
unset label 1
unset label 2
}
unset multiplot
reset
如果所有的绘图都可以通过相同的行语法来完成,那么我建议使用 do-loop(如上例所示)而不是每次都复制它。
请注意,每次绘制图表时,gnuplot
都会放置标签 1 和 2。这就是为什么我将 unset label 1
和 unset label 2
放在 do 循环中的原因,这样标签就放在第一次迭代中。
如果你想要类似于你提供的例子的东西,那么我推荐使用这个脚本(通过评论解释):
#!/usr/local/bin/gnuplot
datafile='tmp.dat' # file to plot
# parameters to configure margins of each graph
x0=0.1 # left margin all graphs
y0=0.99 # top margin all graphs
lengthx=0.4 # horizonal length of each graph
lengthy=0.4 # vertical length of each graph
spacex=0.04 # horizontal space between each graph
spacey=0.04 # vertical space between each graph
# This is a macro: configure the top, right, left, and bottom margins of each graph.
# It will depend on the value of i and j.
set macro
i=0; j=0;
SETMARGINS = "set tmargin at screen (y0-i*(lengthy+spacey));\
set bmargin at screen (y0-i*(lengthy+spacey)-lengthy);\
set lmargin at screen (x0+j*(lengthx+spacex));\
set rmargin at screen (x0+j*(lengthx+spacex)+lengthx)"
# Assuming all plots have the same x and y range. If not, set it in each plot below
set xrange [-1.5:1.5]
set yrange [-4:4]
# general setting for plot titles
set title offset -3,-3
# don't worry about the axis labels for now
unset xlabel
unset ylabel
#############################################################
set multiplot
##### top-left
i=0; j=0;
@SETMARGINS # calling the macro for (i,j)=(0,0)
set format x '' # no numbers in x-axis
set format y '%.1f' # but with numbers in y-axis
set title 'plot 1'
plot datafile u 2:1 w lp pt 7 lt 7 lc rgb 'red' notitle
##### top-right
i=0; j=1;
@SETMARGINS # calling the macro for (i,j)=(0,1)
set format y '' # no numbers in x nor y-axis
set title 'plot 2'
plot datafile u 2:1 w lp pt 7 lt 7 lc rgb 'red' notitle
##### bottom-left
i=1; j=0;
@SETMARGINS # calling the macro for (i,j)=(1,0)
set format xy '%.1f' # numbers in both axes
set title 'plot 3'
plot datafile u 2:1 w lp pt 7 lt 7 lc rgb 'red' notitle
##### bottom-left
i=1; j=1;
@SETMARGINS # calling the macro for (i,j)=(1,1)
set format y '' # no numbers in y-axis
# now we set the x and y labels for the 4th plot, and move them to the desired position
set xlabel 'xlabel' offset screen -0.5*(spacex+lengthx),0.0
set ylabel 'ylabel' offset screen -lengthx-1.5*spacex,0.5*(spacey+lengthy)
set title 'plot 4'
plot datafile u 2:1 w lp pt 7 lt 7 lc rgb 'red' notitle
unset multiplot
reset
更多信息:gnuplotting
我正在使用 gnuplot 用 4 个不同的图形绘制一张图片。它们的 x 轴和 y 轴的标签具有相同的含义。如果我这样画:
set multiplot layout 2,2 rowsfirst
set xlabel "x"
set ylabel "y"
set title offset -3,-3
set xrange [20:70]
set yrange [0:15000]
set title "Plot 1"
plot 'data5.list' u 2:1 w lp pt 7 lt 7 lc rgb 'red' notitle
set xrange [20:70]
set yrange [0:15000]
set title "Plot 2"
plot 'data5.list' u 2:1 w lp pt 7 lt 7 lc rgb 'red' notitle
set xrange [20:70]
set yrange [0:15000]
set title "Plot 3"
plot 'data5.list' u 2:1 w lp pt 7 lt 7 lc rgb 'red' notitle
set xrange [20:70]
set yrange [0:15000]
set title "Plot 4"
plot 'data5.list' u 2:1 w lp pt 7 lt 7 lc rgb 'red' notitle
unset multiplot
我有所有四个图表及其标签,但我想为所有四个图表都添加一个标签,如此 example .
我尝试为其他 3 个图使用未设置的标签,但我只在第一个图上获得标签,而另一个根本没有标签。
您可能希望使用 set label
,而不是使用 xlabel
和 ylabel
。例如,
#!/usr/local/bin/gnuplot
datafile='tmp.dat' # file to plot
set xlabel " " # no x-label
set ylabel " " # no y-label
# assuming all plots have same x and y range
set xrange [-2:2]
set yrange [-4:4]
# same setting for all graph titles
set title offset -3,-3
# puts x-label and y-label manually
set label 1 'x axis' at screen 0.49,0.02
set label 2 'y axis' at screen 0.01,0.5 rotate by 90
# now the graphs: notice that rowsfirst is given by default
set multiplot layout 2,2
do for [i=1:4]{
set title 'plot '.i
plot datafile u 2:1 w lp pt 7 lt 7 lc rgb 'red' notitle
unset label 1
unset label 2
}
unset multiplot
reset
如果所有的绘图都可以通过相同的行语法来完成,那么我建议使用 do-loop(如上例所示)而不是每次都复制它。
请注意,每次绘制图表时,gnuplot
都会放置标签 1 和 2。这就是为什么我将 unset label 1
和 unset label 2
放在 do 循环中的原因,这样标签就放在第一次迭代中。
如果你想要类似于你提供的例子的东西,那么我推荐使用这个脚本(通过评论解释):
#!/usr/local/bin/gnuplot
datafile='tmp.dat' # file to plot
# parameters to configure margins of each graph
x0=0.1 # left margin all graphs
y0=0.99 # top margin all graphs
lengthx=0.4 # horizonal length of each graph
lengthy=0.4 # vertical length of each graph
spacex=0.04 # horizontal space between each graph
spacey=0.04 # vertical space between each graph
# This is a macro: configure the top, right, left, and bottom margins of each graph.
# It will depend on the value of i and j.
set macro
i=0; j=0;
SETMARGINS = "set tmargin at screen (y0-i*(lengthy+spacey));\
set bmargin at screen (y0-i*(lengthy+spacey)-lengthy);\
set lmargin at screen (x0+j*(lengthx+spacex));\
set rmargin at screen (x0+j*(lengthx+spacex)+lengthx)"
# Assuming all plots have the same x and y range. If not, set it in each plot below
set xrange [-1.5:1.5]
set yrange [-4:4]
# general setting for plot titles
set title offset -3,-3
# don't worry about the axis labels for now
unset xlabel
unset ylabel
#############################################################
set multiplot
##### top-left
i=0; j=0;
@SETMARGINS # calling the macro for (i,j)=(0,0)
set format x '' # no numbers in x-axis
set format y '%.1f' # but with numbers in y-axis
set title 'plot 1'
plot datafile u 2:1 w lp pt 7 lt 7 lc rgb 'red' notitle
##### top-right
i=0; j=1;
@SETMARGINS # calling the macro for (i,j)=(0,1)
set format y '' # no numbers in x nor y-axis
set title 'plot 2'
plot datafile u 2:1 w lp pt 7 lt 7 lc rgb 'red' notitle
##### bottom-left
i=1; j=0;
@SETMARGINS # calling the macro for (i,j)=(1,0)
set format xy '%.1f' # numbers in both axes
set title 'plot 3'
plot datafile u 2:1 w lp pt 7 lt 7 lc rgb 'red' notitle
##### bottom-left
i=1; j=1;
@SETMARGINS # calling the macro for (i,j)=(1,1)
set format y '' # no numbers in y-axis
# now we set the x and y labels for the 4th plot, and move them to the desired position
set xlabel 'xlabel' offset screen -0.5*(spacex+lengthx),0.0
set ylabel 'ylabel' offset screen -lengthx-1.5*spacex,0.5*(spacey+lengthy)
set title 'plot 4'
plot datafile u 2:1 w lp pt 7 lt 7 lc rgb 'red' notitle
unset multiplot
reset
更多信息:gnuplotting