1

我使用以下脚本生成了一个绘图,结果如下图所示。很难看到,但实际上每次plot调用函数时都会一遍又一遍地绘制 xlabel、ylabel、title 和 tic 数字multiplot。在想法中,我如何避免这种情况,只绘制图表而不做其他任何事情?如果我取消设置标题、抽动等然后进行绘图,则图形不会绘制在与框架相同的区域,并且会延伸到左侧 y 轴所在的位置。

#set datafile separator ' '
set samples 1000

set term tikz size 17cm,10cm dashed
set out 'MosfetClassAbPower.tex'

unset key

set border lw 2

set style fill transparent solid 0.5 noborder

set title 'MOSFET $\mathrm{I_D}$ Vs Time'
set ylabel 'Drain Current [$\mu$A]'
set xlabel 'Time [ms]'

set xrange [0:4]
set xtics 0,0.5,4
set mxtics 4

set yrange [-50:450]
set mytics 4

set rmargin 5
set label 1 '\SI{60}{\micro\ampere}' at 4.02,60


set multiplot

set grid mxtics mytics lt -1 lc rgb 'gray90'
plot NaN notitle
unset grid

set grid xtics ytics lt -1 lc rgb 'gray70'
plot NaN notitle
unset grid

plot NaN notitle

Id(x) = 347*sin(2*3.14*x) + 60
ID(x) = Id(x) >= 0 ? Id(x) : 0
plot    ID(x) w filledcurves above y1=0 lc rgb 'light-blue',\
        60 w lines lt 2 lw 3 lc rgb 'gray60',\
        ID(x) w lines lt 1 lw 5 lc rgb 'navy'

plot NaN notitle

unset multiplot


set out

结果

我试图防止曲线突出框架。编辑:

reset

#set term tikz size 17cm,10cm dashed standalone header '\usepackage{siunitx}'
#set out 'MosfetClassAbPower.tex'
#TSCALE = 1.0

set terminal pdfcairo dashed
set out 'MosfetClassAbPowerFixed.pdf'
TSCALE = 20.0 # use this value for e.g. pdfcairo or cairolatex

TITLE = 'MOSFET $I_D$ Vs Time'
YLABEL = 'Drain Current (in \si{\uA})'
XLABEL = 'Time (in \si{\ms})'

set style fill transparent solid 0.5 noborder

set xrange [0:4]
set xtics 0,0.5,4
set mxtics 4

set yrange [-50:450]
set mytics 4

set rmargin 5
LABEL = '\SI{60}{\uA}'
set label 1 LABEL at graph 1.01, first 60

unset key
set samples 1000

set multiplot

set title TITLE
set ylabel YLABEL
set xlabel XLABEL
unset border
set tics scale 0,0.001
set grid mxtics mytics lt -1 lc rgb 'gray90'
plot NaN
unset grid

# keep the current margins for all following plots
set lmargin at screen TSCALE*GPVAL_TERM_XMIN/(1.0*GPVAL_TERM_XSIZE)
set rmargin at screen TSCALE*GPVAL_TERM_XMAX/(1.0*GPVAL_TERM_XSIZE)
set tmargin at screen TSCALE*GPVAL_TERM_YMAX/(1.0*GPVAL_TERM_YSIZE)
set bmargin at screen TSCALE*GPVAL_TERM_YMIN/(1.0*GPVAL_TERM_YSIZE)

# unset almost everything
unset border
unset label
unset xlabel
unset ylabel
set format x ''
set format y ''
unset title

set grid xtics ytics lt -1 lc rgb 'gray70'
plot NaN
unset grid

Id(x) = 347*sin(2*3.14*x) + 60
ID(x) = Id(x) >= 0 ? Id(x) : 0
plot    ID(x) w filledcurves above y1=0 lc rgb 'light-blue',\
        60 w lines lt 2 lw 3 lc rgb 'gray60',\
        ID(x) w lines lt 1 lw 5 lc rgb 'navy'

# overdraw borders on left, right, top, bottom
set object 1 rectangle from screen 0, screen 0 to graph 0, screen 1 back \
  fillstyle solid noborder
set object 2 rectangle from graph 1, screen 0 to screen 1, screen 1 back \
  fillstyle solid noborder
set object 3 rectangle from screen 0, graph 1 to screen 1, screen 1 back \
  fillstyle solid noborder
set object 4 rectangle from screen 0, screen 0 to screen 1, graph 0 back \
  fillstyle solid noborder
plot NaN
unset object 1
unset object 2
unset object 3
unset object 4

set title TITLE
set ylabel YLABEL
set xlabel XLABEL
set label 1 LABEL at graph 1.01, first 60
set format x
set format y
set tics scale 1,0.5 front
set border
set border lw 2
plot NaN

unset multiplot
set out
4

1 回答 1

2

不可能为所有绘图元素设置不同的层并任意堆叠它们。你必须玩弄set各种unset元素。

  1. 为了只绘制一次抽动,我将它们的比例设置为0(这适用于主要抽动,但不适用于我使用的次要抽动0.001)。

  2. 在绘制次要网格线后,我修复了边距(请参阅Gnuplot:存储绘图区域尺寸以备后用)。

  3. 取消设置不应再次绘制的所有内容(label, object, arrow, tic 标签等)。不要unset tics,因为我们想最后绘制它们,所以只使用set format x ''绘制抽动,而不是它们的标签。

  4. 将抽动设置为其默认比例,并在最后一个绘图之前设置边框,以将它们绘制在网格线上方和绘图上方。

    reset
    set term tikz size 17cm,10cm dashed standalone header '\usepackage{siunitx}'
    set out 'MosfetClassAbPower.tex'
    TSCALE = 1.0
    
    # set terminal pdfcairo
    # TSCALE = 20.0 # use this value for e.g. pdfcairo or cairolatex
    
    set style fill transparent solid 0.5 noborder
    
    set title 'MOSFET $I_D$ Vs Time'
    set ylabel 'Drain Current (in \si{\uA})'
    set xlabel 'Time (in \si{\ms})'
    
    set xrange [0:4]
    set xtics 0,0.5,4
    set mxtics 4
    
    set yrange [-50:450]
    set mytics 4
    
    set rmargin 5
    set label 1 '\SI{60}{\uA}' at graph 1.01, first 60
    
    unset key
    set samples 1000
    
    set multiplot
    
    unset border
    set tics scale 0,0.001
    set grid mxtics mytics lt -1 lc rgb 'gray90'
    plot NaN
    unset grid
    
    # keep the current margins for all following plots
    set lmargin at screen TSCALE*GPVAL_TERM_XMIN/(1.0*GPVAL_TERM_XSIZE)
    set rmargin at screen TSCALE*GPVAL_TERM_XMAX/(1.0*GPVAL_TERM_XSIZE)
    set tmargin at screen TSCALE*GPVAL_TERM_YMAX/(1.0*GPVAL_TERM_YSIZE)
    set bmargin at screen TSCALE*GPVAL_TERM_YMIN/(1.0*GPVAL_TERM_YSIZE)
    
    # unset almost everything
    unset border
    unset label
    unset xlabel
    unset ylabel
    set format x ''
    set format y ''
    unset title
    
    set grid xtics ytics lt -1 lc rgb 'gray70'
    plot NaN
    unset grid
    
    set tics scale 1,0.5 front
    set border
    set border lw 2
    
    Id(x) = 347*sin(2*3.14*x) + 60
    ID(x) = Id(x) >= 0 ? Id(x) : 0
    plot    ID(x) w filledcurves above y1=0 lc rgb 'light-blue',\
            60 w lines lt 2 lw 3 lc rgb 'gray60',\
            ID(x) w lines lt 1 lw 5 lc rgb 'navy'
    
    unset multiplot
    set out
    

结果:

在此处输入图像描述

现在的顺序是:

  1. 次要网格线
  2. 主要网格线
  3. 曲线
  4. 边界,抽动

请注意,我还做了一些其他微小的更改:您可以使用例如graph坐标来设置标签。并对标签文本进行了一些调整。

编辑:

Cairolatex 或 epslatex

上述过程适用于任何同时处理文本和图形的终端,但不适用于类似的终端cairolatex,并且epslatexmultiplot模式下也只知道两个文本层:

  1. front层,包含所有用front关键字放置的文本。
  2. 图形,包含所有plot命令的所有图形元素(也在multiplot模式下)。
  3. back层,包含所有用back关键字放置的文本。

这可能会成为一个问题,当人们想用白色物体覆盖图形的某些部分(突出的线),但不能将例如放在xlabel前面时。这是一个示例,它也适用于cairolatex

reset

set terminal cairolatex pdf dashed color standalone header "\\usepackage{siunitx}" size 17cm,10cm
set output 'MosfetClassAbPowerFixed.tex'

TITLE = 'MOSFET $I_D$ Vs Time'
YLABEL = 'Drain Current (in \si{\uA})'
XLABEL = 'Time (in \si{\ms})'

set style fill transparent solid 0.5 noborder

set xrange [0:4]
set xtics 0,0.5,4
set mxtics 4
set yrange [-50:450]
set mytics 4

RMARGIN=0.92
LMARGIN=0.1
set rmargin at screen RMARGIN
set lmargin at screen LMARGIN
set tmargin at screen 0.91
set bmargin at screen 0.11

unset key
set samples 1000

set multiplot

# first plot the minor grid lines
unset border
set tics scale 0,0.001 format ''
set grid mxtics mytics lt -1 lc rgb 'gray90'
plot NaN

# now plot the major grid lines
unset grid
set grid xtics ytics lt -1 lc rgb 'gray70'
plot NaN
unset grid

# plot the actual curve
# overdraw borders on left and right
set object rectangle from graph -0.005, graph 0 to screen LMARGIN, graph 1 front \
  fillstyle solid noborder
set object rectangle from screen RMARGIN, graph 0 to graph 1.005, graph 1 front \
  fillstyle solid noborder
Id(x) = 347*sin(2*3.14*x) + 60
ID(x) = Id(x) >= 0 ? Id(x) : 0
plot    ID(x) w filledcurves above y1=0 lc rgb 'light-blue',\
        60 w lines lt 2 lw 3 lc rgb 'gray60',\
        ID(x) w lines lt 1 lw 5 lc rgb 'navy'

unset object
# plot all tics and labels
LABEL = '\SI{60}{\uA}'
set label 1 LABEL at graph 1.01, first 60 front
set title TITLE
set ylabel YLABEL
set xlabel XLABEL
set tics scale 1,0.5 format
set border
set border lw 2

plot NaN

unset multiplot
set out

由于只有三层,我在绘图边框和 tic 标签之间放置了细长的白色矩形。要将对象绘制在绘图区域之外,需要在坐标中使用至少一个坐标值screen,否则会被裁剪。

与第一个示例相反,我对整个情节使用了固定边距,这是我更喜欢的。

这给出了:

在此处输入图像描述

于 2013-10-02T07:56:19.503 回答