调整多色图中每个绘图的比例以均匀分布

时间:2015-05-01 10:09:07

标签: gnuplot

我正在尝试使用gnuplot中的“​​multiplot”选项绘制多个图形。 我的情节如下图所示。

我有一个小问题,但我不知道如何解决这个问题。问题在于每个单独情节的规模。如果一个通知,每个图a,b,c,d和e的比例是不同的。对于每个绘图,我使用了不同的set xrange值。所以,我理解gnuplot试图拉伸图以适应给定的宽度限制。因此,沿水平轴的刻度不均匀间隔。

我希望每个绘图的刻度均匀分布,尤其是水平轴。

下面我给出了您的观点的完整代码。

我如何完成这项工作?

非常感谢提前。

enter image description here

#!/usr/bin/gnuplot

########################################################################################

mpl_top    = 0.4 #inch  outer top margin, title goes here
mpl_bot    = 0.7 #inch  outer bottom margin, x label goes here
mpl_left   = 0.3 #inch  outer left margin, y label goes here    #vj
mpl_right  = 0.8 #inch  outer right margin, y2 label goes here  #vj
mpl_height = 1.0 #inch  height of individual plots
mpl_width  = 2.2 #inch  width of individual plots       #vj  
mpl_dx     = 0.1 #inch  inter-plot horizontal spacing
mpl_dy     = 0.4 #inch  inter-plot vertical spacing
mpl_ny     = 5   #number of rows
mpl_nx     = 1   #number of columns

# calculate full dimensions
xsize = mpl_left+mpl_right+(mpl_width*mpl_nx)+(mpl_nx-1)*mpl_dx
ysize = mpl_top+mpl_bot+(mpl_ny*mpl_height)+(mpl_ny-1)*mpl_dy

# placement functions
#   rows are numbered from bottom to top
bot(n) = (mpl_bot+(n-1)*mpl_height+(n-1)*mpl_dy)/ysize
top(n)  = 1-((mpl_top+(mpl_ny-n)*(mpl_height+mpl_dy))/ysize)
#   columns are numbered from left to right
left(n) = (mpl_left+(n-1)*mpl_width+(n-1)*mpl_dx)/xsize
right(n)  = 1-((mpl_right+(mpl_nx-n)*(mpl_width+mpl_dx))/xsize)

#=================================================================

#set terminal postscript eps enhanced color dl 2.0 size xsize,ysize "Helvetica" 28
##set encoding iso_8859_1
##set tics scale 1
#set output 'nxm_plot.eps'


set terminal pngcairo size 650,650 enhanced dash #font "Arial-Bold,13" #fontscale 1.20
set output "Fill-Multi-plot-LDP-lyoSystemLast50ns.png"

set encoding iso_8859_1

set offsets
set autoscale fix
set size 1,1
set nokey

# define x-axis settings for all subplots
#set xrange [-30:30]
set yrange [0:3]
set xlabel ''
#set format x ''
set xtic auto
#set xtics 5    #pi
#set mxtics 4


#### VJ DEFINITION
#set style line 4 lt 4 lw 10    # Please DISABLE pause -1 
#########################################################################################

set style line 1 lt 1 lw 1.5  lc rgb "red"
set style line 2 lt 3 lw 1.5  lc rgb "red"
set style line 3 lt 5 lw 1.5  lc rgb "red"

set style line 4 lt 1 lw 1.5  lc rgb "black"
set style line 5 lt 3 lw 1.5  lc rgb "black"
set style line 6 lt 5 lw 1.5  lc rgb "black"

set style line 7 lt 1 lw 1.5  lc rgb "green"
set style line 8 lt 3 lw 1.5  lc rgb "green"
set style line 9 lt 5 lw 1.5  lc rgb "green"

set style line 10 lt 1 lw 1.5  lc rgb "blue"
set style line 11 lt 3 lw 1.5  lc rgb "blue"
set style line 12 lt 5 lw 1.5  lc rgb "blue"

set style line 13 lt 1 lw 1.5  lc rgb "magenta"
set style line 14 lt 3 lw 1.5  lc rgb "magenta"
set style line 15 lt 5 lw 1.5  lc rgb "magenta"

set style line 16 lt 1 lw 1.5  lc rgb "#6495ED"
set style line 17 lt 3 lw 1.5  lc rgb "#6495ED"
set style line 18 lt 5 lw 1.5  lc rgb "#6495ED"

###################################################################################################
set macro
#ylabelFONT="font 'arial,16'"
labelFONT="font 'Arial,16'"
scaleFONT="font 'Arial-Bold,14'"
scaleFONtt="font 'Helvetica,10'"
keyFONT="font 'Arial,12'"
#graph="using 1:2 with lines lw 1 "

###################################################################################################


# start plotting
set multiplot

#-----------------------------------------------
# subplot  1-5
#  set horizontal margins for first column
set lmargin at screen left(1)
set rmargin at screen right(1)
#  set horizontal margins for third row (top)
set tmargin at screen top(5)
set bmargin at screen bot(5)


set label "(a)" at -1.5,2.5  @labelFONT
set title ''
unset ylabel
set xrange [-20.0:20.0]
set format y "" #"%-2.1f"
plot    "malto12per-000-050ns_only_HEAD.dat"       using 1:2 title  '1-050ns'  w  l  ls  1  ,\
        "malto12per-000-050ns_only_TAIL.dat"       using 1:2 title  '1-050ns'  w  l  ls  2  ,\
    "malto12per-000-050ns_only_WATER.dat"      using 1:2 title  '1-050ns'  w  l  ls  3  ,\
    "malto12per-051-100ns_only_HEAD.dat"       using 1:2 title  '51-100ns'  w  l  ls  4  ,\
    "malto12per-051-100ns_only_TAIL.dat"       using 1:2 title  '51-100ns'  w  l  ls  5  ,\
    "malto12per-051-100ns_only_WATER.dat"      using 1:2 title  '51-100ns'  w  l  ls  6  ,\
    "malto12per-101-150ns_only_HEAD.dat"       using 1:2 title  '101-150ns'  w  l  ls  7  ,\
    "malto12per-101-150ns_only_TAIL.dat"       using 1:2 title  '101-150ns'  w  l  ls  8  ,\
    "malto12per-101-150ns_only_WATER.dat"      using 1:2 title  '101-150ns'  w  l  ls  9  ,\
    "malto12per-151-200ns_only_HEAD.dat"       using 1:2 title  '151-200ns'  w  l  ls  10 ,\
    "malto12per-151-200ns_only_TAIL.dat"       using 1:2 title  '151-200ns'  w  l  ls  11 ,\
    "malto12per-151-200ns_only_WATER.dat"      using 1:2 title  '151-200ns'  w  l  ls  12 ,\
    "malto12per-201-250ns_only_HEAD.dat"       using 1:2 title  '201-250ns'  w  l  ls  13 ,\
    "malto12per-201-250ns_only_TAIL.dat"       using 1:2 title  '201-250ns'  w  l  ls  14 ,\
    "malto12per-201-250ns_only_WATER.dat"      using 1:2 title  '201-250ns'  w  l  ls  15 ,\
    "malto12per-251-300ns_only_HEAD.dat"       using 1:2 title  '251-300ns'  w  l  ls  16 ,\
    "malto12per-251-300ns_only_TAIL.dat"       using 1:2 title  '251-300ns'  w  l  ls  17 ,\
    "malto12per-251-300ns_only_WATER.dat"      using 1:2 title  '251-300ns'  w  l  ls  18 
;


#-----------------------------------------------
# subplot  1-4 at top most
#  set horizontal margins for first column
set lmargin at screen left(1)
set rmargin at screen right(1)
#  set horizontal margins for third row (top)
set tmargin at screen top(4)
set bmargin at screen bot(4)


unset label
set label "(b)" at -1.5,2.5  @labelFONT
set title ''
unset ylabel
set xtics
set xrange [-26.2:26.2]
set format y "" #"%-2.1f"


plot    "malto23per-000-050ns_only_HEAD.dat"       using 1:2 title  '1-050ns'  w  l  ls  1  ,\
        "malto23per-000-050ns_only_TAIL.dat"       using 1:2 title  '1-050ns'  w  l  ls  2  ,\
        "malto23per-000-050ns_only_WATER.dat"      using 1:2 title  '1-050ns'  w  l  ls  3  ,\
        "malto23per-051-100ns_only_HEAD.dat"       using 1:2 title  '51-100ns'  w  l  ls  4  ,\
        "malto23per-051-100ns_only_TAIL.dat"       using 1:2 title  '51-100ns'  w  l  ls  5  ,\
        "malto23per-051-100ns_only_WATER.dat"      using 1:2 title  '51-100ns'  w  l  ls  6  ,\
        "malto23per-101-150ns_only_HEAD.dat"       using 1:2 title  '101-150ns'  w  l  ls  7  ,\
        "malto23per-101-150ns_only_TAIL.dat"       using 1:2 title  '101-150ns'  w  l  ls  8  ,\
        "malto23per-101-150ns_only_WATER.dat"      using 1:2 title  '101-150ns'  w  l  ls  9  ,\
        "malto23per-151-200ns_only_HEAD.dat"       using 1:2 title  '151-200ns'  w  l  ls  10 ,\
        "malto23per-151-200ns_only_TAIL.dat"       using 1:2 title  '151-200ns'  w  l  ls  11 ,\
        "malto23per-151-200ns_only_WATER.dat"      using 1:2 title  '151-200ns'  w  l  ls  12 ,\
        "malto23per-201-250ns_only_HEAD.dat"       using 1:2 title  '201-250ns'  w  l  ls  13 ,\
        "malto23per-201-250ns_only_TAIL.dat"       using 1:2 title  '201-250ns'  w  l  ls  14 ,\
        "malto23per-201-250ns_only_WATER.dat"      using 1:2 title  '201-250ns'  w  l  ls  15 ,\
        "malto23per-251-300ns_only_HEAD.dat"       using 1:2 title  '251-300ns'  w  l  ls  16 ,\
        "malto23per-251-300ns_only_TAIL.dat"       using 1:2 title  '251-300ns'  w  l  ls  17 ,\
        "malto23per-251-300ns_only_WATER.dat"      using 1:2 title  '251-300ns'  w  l  ls  18
;


#-----------------------------------------------
# subplot  1-3
#  set horizontal margins for first column
set lmargin at screen left(1)
set rmargin at screen right(1)
#  set horizontal margins for second row (middle)
set tmargin at screen top(3)
set bmargin at screen bot(3)


unset label
set label "(c)" at -1.5,2.5  @labelFONT
set title ''
set ylabel "Number Density" @labelFONT
set xrange [-24.2:24.2]
set format y "" #"%-1.1f"
plot    "bcm25perR-000-050ns_only_HEAD.dat"       using 1:2 title  '1-050ns'  w  l  ls  1  ,\
        "bcm25perR-000-050ns_only_TAIL.dat"       using 1:2 title  '1-050ns'  w  l  ls  2  ,\
        "bcm25perR-000-050ns_only_WATER.dat"      using 1:2 title  '1-050ns'  w  l  ls  3  ,\
        "bcm25perR-051-100ns_only_HEAD.dat"       using 1:2 title  '51-100ns'  w  l  ls  4  ,\
        "bcm25perR-051-100ns_only_TAIL.dat"       using 1:2 title  '51-100ns'  w  l  ls  5  ,\
        "bcm25perR-051-100ns_only_WATER.dat"      using 1:2 title  '51-100ns'  w  l  ls  6  ,\
        "bcm25perR-101-150ns_only_HEAD.dat"       using 1:2 title  '101-150ns'  w  l  ls  7  ,\
        "bcm25perR-101-150ns_only_TAIL.dat"       using 1:2 title  '101-150ns'  w  l  ls  8  ,\
        "bcm25perR-101-150ns_only_WATER.dat"      using 1:2 title  '101-150ns'  w  l  ls  9  ,\
        "bcm25perR-151-200ns_only_HEAD.dat"       using 1:2 title  '151-200ns'  w  l  ls  10 ,\
        "bcm25perR-151-200ns_only_TAIL.dat"       using 1:2 title  '151-200ns'  w  l  ls  11 ,\
        "bcm25perR-151-200ns_only_WATER.dat"      using 1:2 title  '151-200ns'  w  l  ls  12 ,\
        "bcm25perR-201-250ns_only_HEAD.dat"       using 1:2 title  '201-250ns'  w  l  ls  13 ,\
        "bcm25perR-201-250ns_only_TAIL.dat"       using 1:2 title  '201-250ns'  w  l  ls  14 ,\
        "bcm25perR-201-250ns_only_WATER.dat"      using 1:2 title  '201-250ns'  w  l  ls  15 ,\
        "bcm25perR-251-300ns_only_HEAD.dat"       using 1:2 title  '251-300ns'  w  l  ls  16 ,\
        "bcm25perR-251-300ns_only_TAIL.dat"       using 1:2 title  '251-300ns'  w  l  ls  17 ,\
        "bcm25perR-251-300ns_only_WATER.dat"      using 1:2 title  '251-300ns'  w  l  ls  18
;



#-----------------------------------------------
# subplot  1-2
#  set horizontal margins for first column
set lmargin at screen left(1)
set rmargin at screen right(1)
#  set horizontal margins for second row (middle)
set tmargin at screen top(2)
set bmargin at screen bot(2)


unset label
set label "(d)" at -1.5,2.5  @labelFONT
set title ''
unset ylabel
set xrange [-24.8:24.8]
set format y "" #"%-1.1f"
plot    "bcm25perS-000-050ns_only_HEAD.dat"       using 1:2 title  '1-050ns'  w  l  ls  1  ,\
        "bcm25perS-000-050ns_only_TAIL.dat"       using 1:2 title  '1-050ns'  w  l  ls  2  ,\
        "bcm25perS-000-050ns_only_WATER.dat"      using 1:2 title  '1-050ns'  w  l  ls  3  ,\
        "bcm25perS-051-100ns_only_HEAD.dat"       using 1:2 title  '51-100ns'  w  l  ls  4  ,\
        "bcm25perS-051-100ns_only_TAIL.dat"       using 1:2 title  '51-100ns'  w  l  ls  5  ,\
        "bcm25perS-051-100ns_only_WATER.dat"      using 1:2 title  '51-100ns'  w  l  ls  6  ,\
        "bcm25perS-101-150ns_only_HEAD.dat"       using 1:2 title  '101-150ns'  w  l  ls  7  ,\
        "bcm25perS-101-150ns_only_TAIL.dat"       using 1:2 title  '101-150ns'  w  l  ls  8  ,\
        "bcm25perS-101-150ns_only_WATER.dat"      using 1:2 title  '101-150ns'  w  l  ls  9  ,\
        "bcm25perS-151-200ns_only_HEAD.dat"       using 1:2 title  '151-200ns'  w  l  ls  10 ,\
        "bcm25perS-151-200ns_only_TAIL.dat"       using 1:2 title  '151-200ns'  w  l  ls  11 ,\
        "bcm25perS-151-200ns_only_WATER.dat"      using 1:2 title  '151-200ns'  w  l  ls  12 ,\
        "bcm25perS-201-250ns_only_HEAD.dat"       using 1:2 title  '201-250ns'  w  l  ls  13 ,\
        "bcm25perS-201-250ns_only_TAIL.dat"       using 1:2 title  '201-250ns'  w  l  ls  14 ,\
        "bcm25perS-201-250ns_only_WATER.dat"      using 1:2 title  '201-250ns'  w  l  ls  15 ,\
        "bcm25perS-251-300ns_only_HEAD.dat"       using 1:2 title  '251-300ns'  w  l  ls  16 ,\
        "bcm25perS-251-300ns_only_TAIL.dat"       using 1:2 title  '251-300ns'  w  l  ls  17 ,\
        "bcm25perS-251-300ns_only_WATER.dat"      using 1:2 title  '251-300ns'  w  l  ls  18
;


#-----------------------------------------------
# subplot  1-1
#  set horizontal margins for first column
set lmargin at screen left(1)
set rmargin at screen right(1)
#  set horizontal margins for first row (bottom)
set tmargin at screen top(1)
set bmargin at screen bot(1)


unset label
set label "(e)" at -1.5,2.5  @labelFONT
set title ''
# now set a label and tic marks for the x-axis
set xlabel "Distance / ({\305})"    @labelFONT
unset ylabel
set xrange [-24.1:24.1]
set format y "" # "%-1.1f"

plot    "bcm25perRS-000-050ns_only_HEAD.dat"       using 1:2 title  '1-050ns'  w  l  ls  1  ,\
        "bcm25perRS-000-050ns_only_TAIL.dat"       using 1:2 title  '1-050ns'  w  l  ls  2  ,\
        "bcm25perRS-000-050ns_only_WATER.dat"      using 1:2 title  '1-050ns'  w  l  ls  3  ,\
        "bcm25perRS-051-100ns_only_HEAD.dat"       using 1:2 title  '51-100ns'  w  l  ls  4  ,\
        "bcm25perRS-051-100ns_only_TAIL.dat"       using 1:2 title  '51-100ns'  w  l  ls  5  ,\
        "bcm25perRS-051-100ns_only_WATER.dat"      using 1:2 title  '51-100ns'  w  l  ls  6  ,\
        "bcm25perRS-101-150ns_only_HEAD.dat"       using 1:2 title  '101-150ns'  w  l  ls  7  ,\
        "bcm25perRS-101-150ns_only_TAIL.dat"       using 1:2 title  '101-150ns'  w  l  ls  8  ,\
        "bcm25perRS-101-150ns_only_WATER.dat"      using 1:2 title  '101-150ns'  w  l  ls  9  ,\
        "bcm25perRS-151-200ns_only_HEAD.dat"       using 1:2 title  '151-200ns'  w  l  ls  10 ,\
        "bcm25perRS-151-200ns_only_TAIL.dat"       using 1:2 title  '151-200ns'  w  l  ls  11 ,\
        "bcm25perRS-151-200ns_only_WATER.dat"      using 1:2 title  '151-200ns'  w  l  ls  12 ,\
        "bcm25perRS-201-250ns_only_HEAD.dat"       using 1:2 title  '201-250ns'  w  l  ls  13 ,\
        "bcm25perRS-201-250ns_only_TAIL.dat"       using 1:2 title  '201-250ns'  w  l  ls  14 ,\
        "bcm25perRS-201-250ns_only_WATER.dat"      using 1:2 title  '201-250ns'  w  l  ls  15 ,\
        "bcm25perRS-251-300ns_only_HEAD.dat"       using 1:2 title  '251-300ns'  w  l  ls  16 ,\
        "bcm25perRS-251-300ns_only_TAIL.dat"       using 1:2 title  '251-300ns'  w  l  ls  17 ,\
        "bcm25perRS-251-300ns_only_WATER.dat"      using 1:2 title  '251-300ns'  w  l  ls  18
;

#----------------------------------------------------
set size 0.3,0.5
set origin -0.56,-0.35
set bmargin at screen 0
#set key at screen 0.85,screen 0.45 Left reverse spacing 1.0 samplen 1.0 maxcols 1 maxrows 6 @keyFONT
set key at screen 1.00,screen 0.45 maxcols 3 maxrows 6 @keyFONT
#set key center left  
set border 0 
unset xlabel
unset ylabel
unset label
unset tics
set format x ""
set format y ""
set yrange [0:1]
plot 2 ls 1 t '1-50ns', \
     2 ls 4 t '51-100ns', \
     2 ls 7 t '101-150ns', \
     2 ls 10    t '151-200ns', \
     2 ls 13    t '201-250ns', \
     2 ls 16    t '251-300ns'
;

unset multiplot

1 个答案:

答案 0 :(得分:3)

如果我理解正确,您希望所有图表的单位长度相同。您可以使用do循环动态设置边距以获得此效果。基本上你需要在开头和你将找到的最大范围内定义xranges(你也可以通过更多的工作自动完成)。以下代码应该按照您的要求执行(阅读注释以获取更多信息):

# This function returns the ranges for each graph,
# I have only defined 3
range(i)=(i == 1 ? "-20 20" : \
          i == 2 ? "-25 25" : \
          i == 3 ? "-15 15" : 1/0)

# Number of graphs and maxrange
N = 3; maxrange = 50.

set xtics 5.

set multiplot

# Loop
do for [i=1:N] {
# Set the margins
set tmargin at screen 0.98-(i-1.)/N
set bmargin at screen 0.74-(i-1.)/N
# Set range and calculate total range for graph i
set xrange [word(range(i),1) : word(range(i),2)]
totalrange = word(range(i),2) - word(range(i),1)
# Center the graphs at 0.55 and scale them depending on their range
set lmargin at screen 0.55-0.43*totalrange/maxrange
set rmargin at screen 0.55+0.43*totalrange/maxrange
# Plot
plot sin(x) not
}

enter image description here

当然,这里有足够的定制空间。

您还可以根据标签i定义您的功能,以便它们通过循环进行更改:

f(x,i) = (i == 1 ? sin(x) : \
          i == 2 ? cos(x) : \
          i == 3 ? tan(x) : 1/0)
.
.
.
plot f(x,i)

如果您有数据文件,可以这样做:

datafiles = "data1 data2 data3"
.
.
.
plot word(datafiles,i)

同样的风格等:

set style line 1 lw 1
set style line 2 lw 2
set style line 3 lw 3
.
.
.
plot f(x,i) ls i

最后,如果你想要完全控制(例如你正在混合函数和数据文件或其他东西),你可以在for循环中定义if语句:

.
.
.
if (i == 1) {plot sin(x)}
if (i == 2) {plot cos(x)}
if (i == 3) {plot "data1"}