Gnuplot:多曲线图只是曲线而没有轴或标题等 [英] Gnuplot: Multiplot Plot Just Curve Without Axis Or Title etc

查看:86
本文介绍了Gnuplot:多曲线图只是曲线而没有轴或标题等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下脚本来生成图,结果显示在下图中.很难看到,但是实际上每次在multiplot中调用plot函数时,实际上一遍又一遍地绘制xlabel,ylabel,标题和tic数字.在想法中,我如何才能避免这种情况,而仅画出其他任何图形?如果我取消设置标题,抽签等然后绘图,则该图将不会在与框架相同的区域中绘图,并且会向左y轴所在的区域显示.

I've used the following script to generate a plot and the result is shown in the figure below. It is hard to see, but the xlabel, ylabel, title and tic numbers have actually been drawn over and over again each time a plot function was called while in multiplot. In ideas how I can avoid this and just plot the graph without anything else? If I unset the title, tics etc and then plot, then the graph does not plot in the same area as the frame and petrudes into where the left y-axis is.

#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

我试图防止曲线在框架上突出.

My attempt at preventing the curve from protruding over the frame.

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

推荐答案

不可能为所有绘图元素设置不同的图层并任意堆叠它们.您必须使用setunset处理各种元素.

It is not possible, to set different layers for all plot elements and stack them arbitrarily. You must play around with set and unset for the various elements.

  1. 为了只绘制一次抽线,我将其比例设置为0(这适用于主要抽签,但不适用于次要抽签,在我使用0.001的情况下).

  1. In order to have the tics drawn only once, I set their scale to 0 (this works for the major tics, but not for the minor tics, where I use 0.001).

我会在绘制次网格线后固定边距(请参见 Gnuplot:存储绘图区域尺寸以供以后使用).

I fix the margins after the minor grid lines are drawn (see Gnuplot: Store plot area dimensions for later use).

取消所有不应再次绘制的内容(labelobjectarrow,抽签标签等).不要unset tics,因为我们想最后绘制它们,所以只需使用set format x ''绘制tic,而不是它们的标签即可.

Unset everything, which shouldn't be drawn again (label, object, arrow, tics labels etc). Do not unset tics, because we want to drawn them last, so just use set format x '' to draw the tics, but not their labels.

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

Set the tics to their default scale, and set the border before the last plot, to have them drawn above the grid lines and above the plot.

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坐标以设置标签.以及标签文本的一些调整.

Note, that I made some other tiny changes: You can use e.g. graph coordinates to set a label. And some tweaking of the label text.

上面描述的过程适用于同时处理文本和图形的任何终端,但不适用于cairolatexepslatex之类的终端,它们在multiplot模式下也只知道两个文本层:

The proceeding described above works well for any terminal which processes text and graphics together, but not for terminals like cairolatex and epslatex which also in multiplot mode know only two text layer:

  1. front层,包含用front关键字放置的所有文本.
  2. 图形,包含所有plot命令的所有图形元素(也在multiplot模式下).
  3. back层,包含所有用back关键字放置的文本.
  1. front layer, contains all text placed with front keyword.
  2. graphics, contains all graphical elements of all plot commands (also in multiplot mode).
  3. back layer, contains all text placed with back keyword.

当一个人想要用白色物体覆盖图形的某些部分(突出的线条),而又不能放例如一个物体时,这可能会成为一个问题. xlabel放在前面.这是一个示例,它也可以与cairolatex一起使用:

This may become a problem, when one wants to cover parts of the graphic (protruding lines) with a white object, but cannot put e.g. the xlabel to the front. Here is an example, which works also with 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坐标中至少使用一个坐标值,否则将被裁剪.

Because of the only three layer, I put thin white rectangles between the plot border and the tic labels. To have the objects drawn outside the plotting area, one needs to use at least one coordinate value in screen coordinates, otherwise they are clipped.

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

As opposed the the first example, I used fixed margins for the whole plot, which I prefer.

这给出了:

这篇关于Gnuplot:多曲线图只是曲线而没有轴或标题等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆