【问题标题】:Position of tic marks in GnuplotGnuplot中tic标记的位置
【发布时间】:2015-08-04 13:41:16
【问题描述】:

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

set tics in

将所有的tic标记放在画布内

set tics out

将所有的tic标记放在画布之外

我想要的只是在轴的两侧放置标记,有点像

--l--l--

感谢您的提示!

【问题讨论】:

  • 欢迎来到 StackOverflow,@Eugl!似乎不可能改变抽动的位置,如何绘制轴两次(一个抽动输入,另一个抽动输出)?见here。很抱歉,我还没有安装 gnuplot,我无法正确测试它。
  • 感谢 Paolo 的热烈欢迎,并以某种方式确认无法将 tic 标记重新定位在轴的中间。

标签: gnuplot


【解决方案1】:

正如 cmets 中所说,似乎不可能将抽动放置在轴的两侧。一种解决方法是绘制轴两次,或使用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)
    

    结果:

    这个方法还可以让你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
    

    结果类似:)

【讨论】:

  • vagoberto,感谢您提供详细的解决方法。尤其是手绘抽动非常有帮助。
【解决方案2】:

快速而肮脏的方法:

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

请注意,这会用第二张图叠印您的图表。位图输出应该没问题,但如果您有矢量输出(pdf、eps),则不要这样做,尤其是当您的图形很复杂或包含大量数据点时。它将生成的文件扩大到两倍大小。

Gnuplot 目前 (v 5.0pl1) 没有将抽动放置在轴中心的选项。您必须使用此处显示的解决方法之一。

【讨论】:

    猜你喜欢
    • 2021-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多