Tic标记在Gnuplot中的位置

时间:2015-08-04 13:41:16

标签: gnuplot

我正在寻找一种方法来在轴之间的gnuplot中定位tic标记,但到目前为止我只找到了将它们放入或放出的解决方案:

set tics in

将所有标记放在画布内

set tics out

将画布的所有标记放在画布上

我想要的只是在轴的两侧放置抽搐标记,有些想法是

- 升 - 升 -

感谢您的提示!

2 个答案:

答案 0 :(得分:2)

如评论中所述,似乎不可能将抽动放在轴的两侧。解决方法是将轴绘制两次,或者使用set arrow手动绘制抽搐。

  • 手工绘制抽搐:

    考虑以下设置:

    Xmin = -4.0             # range in x
    Xmax =  4.0
    Ymin = -1.2             # range in y
    Ymax =  1.2
    
    NXtics = 8              # number of Xtics
    NYtics = 4              # number of Ytics
    
    epsX = 0.05             # length of Xtics
    epsY = 0.03             # length of Ytics
    
    dX = (Xmax-Xmin)/NXtics     # distance between Xtics
    dY = (Ymax-Ymin)/NYtics     # distance between Ytics
    

    接下来,我们绘制底部,顶部,左侧和右侧抽动:

    # xtics and x2tics
    do for [i=0:NXtics] {
      posX = Xmin+i*dX
      set arrow from posX,Ymin-epsY to posX,Ymin+epsY nohead front    # bottom
      set arrow from posX,Ymax-epsY to posX,Ymax+epsY nohead front    # top
    }
    
    # ytics and y2tics
    do for [i=0:NYtics] {
      posY = Ymin+i*dY
      set arrow from Xmin-epsX,posY to Xmin+epsX,posY nohead front    # left
      set arrow from Xmax-epsX,posY to Xmax+epsX,posY nohead front    # right
    }
    

    由于您手动绘制抽搐,因此需要配置轴编号和范围:

    set xtics Xmin,dX,Xmax scale 0 offset 0,-epsY
    set ytics Ymin,dY,Ymax scale 0 offset -epsX,0
    
    set xrange [XMIN:XMAX]
    set yrange [YMIN:YMAX]
    

    最后,你的剧情非常复杂:

    plot sin(x)
    

    结果: Plot with tics outside and inside the canvas

    此方法还允许您break the axis

  • 绘制轴两次:

    这种方法更容易;但您需要设置画布的设置边距,并使用multiplot模式:

    set tmargin at screen 0.9   # top margin
    set bmargin at screen 0.2   # bottom
    set lmargin at screen 0.2   # left
    set rmargin at screen 0.9   # right
    
    set yrange [-1.2:1.2]
    set multiplot
      set tics scale 0.5      # scale size of the tics
      plot 2 notitle          # a plot outside the canvas, just to draw the axis
    
      set tics out            # tics outside
      set format xy ''        # delete the numbers
      unset border            # delete the border
      plot sin(x)             # your awesome plot
    unset multiplot
    

    结果类似:)

答案 1 :(得分:0)

快速&肮脏的方法:

set multi
set tics scale 0.5
plot sin(x)/x
set tics out
replot
unset multi

请注意,使用第二个图纸叠印您的图表。对于位图输出应该没问题,但是如果你有矢量输出(pdf,eps)则不要这样做,特别是如果你的图形很复杂或包含很多数据点。它将生成的文件炸成两倍大小。

目前的Gnuplot(v 5.0pl1)没有选择将抽搐置于轴的中心位置。您将不得不使用此处显示的解决方法之一。