我想绘制一些需要 [2-30] 之间的对数刻度 x 轴和 [30-2500] 之间的常规线性 x 轴的图。
这是我想要的图,x轴是部分对数的。
有人可以帮助我吗?预先感谢您。
编辑:固定范围,添加参考图片。
除了用
nonlinear
“搞乱”之外,另一个选择可能只是将你的图分割成一个包含 4 个子图的多图。
像这样的进一步调整...
脚本:
### split log/lin plots
reset session
mySplitX = 0.33 # split point of log/lin in screen coordinates
mySplitY = 0.33 # split point of upper/lower plots in screen coordinates
myLeftMargin = 10
myRightMargin = 4
unset key
set samples 200
set multiplot
set border 7
set origin 0,mySplitY
set size mySplitX,1-mySplitY
set margins myLeftMargin, 0, 0, -1 # l,r,b,t
unset xlabel
set format x ""
set mxtics 10
set logscale x
set xrange [1:30]
set ylabel "my y-axis title"
set ytics nomirror
set mytics 5
set yrange [0:6000]
plot (2500*sin(x)+3000)
set arrow 1 from screen mySplitX, graph 0 to screen mySplitX, graph 1 nohead dt 3
set border 13
set origin mySplitX,mySplitY
set size 1-mySplitX,1-mySplitY
set margins 0, myRightMargin, 0, -1 # l,r,b,t
set xlabel " "
set mxtics 5
unset logscale x
set xrange [30:2500]
unset ylabel
unset ytics
set y2tics
set my2tics 5
set format y2 ""
replot
set border 7
set origin 0,0
set size mySplitX,mySplitY
set margins myLeftMargin, 0, -1, 0 # l,r,b,t
set xlabel "my x-axis title" center offset 28,0
set logscale x
set xrange [1:30]
set format x "%g"
set xtics
set xtics add (30)
set mxtics 10
set ylabel "my Y-label"
set yrange [-750:750]
set ytics 300 nomirror
unset y2tics
plot (500*cos(x))
set border 13
set origin mySplitX,0
set size 1-mySplitX,mySplitY
set margins 0, myRightMargin, -1, 0 # l,r,b,t
set xlabel " "
unset logscale x
set xrange [30:2500]
set mxtics 5
unset ylabel
unset ytics
set y2tics 30 nomirror
set y2range[-75:75]
set format y2 "%g"
set my2tics 4
plot (50*cos(x)) axis x1y2
unset multiplot
### end of script
结果:
补充:
“秘密”只是设置多图的边距和大小,使其看起来像一张图,但具有不同的比例。 在 gnuplot 中检查
help margins
、help origin
、help size
。您基本上可以检查每个关键字help <keyword>
并获得有用的信息。
x 标签仅在第一个图中设置,并带有偏移量 (
help offset
)。
set xlabel "my x-axis title" center offset 28,0
在第二个图中,它只是一个空白区域。
set xlabel " "
脚本:
### split log/lin plots
reset session
mySplitX = 0.33 # split point of log/lin in screen coordinates
unset key
set samples 200
set multiplot
set border 7 # show border at bottom,left,top
set origin 0,0
set size mySplitX,1
set margins -1, 0, -1, -1 # left,right,bottom,top
set xlabel "my x-axis title" center offset 28,0
set format x "%g"
set mxtics 10
set logscale x
set xrange [1:30]
set ylabel "my y-axis title"
set ytics nomirror
set mytics 5
set yrange [0:6000]
plot (2500*sin(x)+3000)
set arrow 1 from screen mySplitX, graph 0 to screen mySplitX, graph 1 nohead dt 3
set border 13 # show border at top,right,bottom
set origin mySplitX,0
set size 1-mySplitX,1
set margins 0, -1, -1, -1 # l,r,b,t
set xlabel " "
set xtics add (30)
set mxtics 5
unset logscale x
set xrange [30:2500]
unset ylabel
unset ytics
set y2tics
set my2tics 5
set format y2 ""
replot
unset multiplot
### end of script
结果:
添加 2:(使用
set nonlinear
的替代解决方案)
实际上,如果您进行坐标转换,您可以使用
set nonlinear
来简化操作(检查 help nonlinear
)。这样做的优点是避免了 multiplot
,允许在交互式终端中放大。
脚本:
### split graph in log/lin-parts via "set nonlinear"
reset session
### create some test data
set table $Data
set samples 100
plot '+' u (x0=10**(log10(30/0.1)/100*$0+log10(0.1))):(sin(0.01*x0)) w table, \
'+' u (x0=$0*(2500-30)/100+30):(sin(0.01*x0)) w table
unset table
xmin = 0.1 # "visible" x-minimum
xsplit = 30 # where to split the graph
xmax = 2500
split = 0.25 # graph ratio of lower log-part
xRangeH = (xmax-xsplit)*split/(1-split) # "hidden" lower x-range
xminH = xsplit - xRangeH # "hidden" lower x-minimum
decades = log10(xsplit/xmin)
f(x) = x<xsplit ? xRangeH/decades*(log10(x/xmin)) + xminH : x
g(x) = x<xsplit ? 10**((x-xminH)/xRangeH*decades )*xmin : x
set xrange[xminH:xmax]
set xtics 500
set mxtics 5
set xtics scale 1,1 add ("0.1" 0.1, "1" 1, "10" 10, "30" 30, "200" 200)
set nonlinear x via f(x) inverse g(x)
set grid x,y
set arrow 1 from xsplit, graph 0 to xsplit, graph 1 lc "blue" dt 2 lw 1.5 nohead
plot $Data u 1:2 w lp pt 7 lc "red" notitle
### end of script
结果: