2
votes

I am looking for a way to position tic marks in gnuplot between the axis, but so far I only found solution to put them in or out:

set tics in

puts all tic marks inside of the canvas

set tics out

puts all tic marks outide of the canvas

All I want is to place tic marks on both sides of the axis, somethink like

--l--l--

Thanks for a hint!

2
Welcome on StackOverflow, @Eugl! It seems not possible change the position of the tics, how about plotting the axis twice (one with tics in and the other one with tics out)? See here. I'm sorry at the moment I haven't gnuplot installed and I cannot test it properly. - Paolo Gibellini
Thank you Paolo for the warm welcome and also for somehow confirm that it is not possible to reposition the tic marks at the middle of the axis. <its always frustrating, if you have to match a style of excel. Still if someone has an easy solution, please give us an explanation. Up to that I will try to use Paolos workaround. - EugI

2 Answers

2
votes

As said in the comments, it seems not possible to place the tics on both sides of the axis. A workaround would be to plot the axis twice, or to draw the tics by hand with the set arrow.

  • Drawing tics by hand:

    Consider the following settings:

    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
    

    Next, we draw the bottom, top, left, and right tics:

    # 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
    }
    

    Since you are drawing the tics by hand, you will need to configure the axis numbers and ranges:

    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]
    

    Finally, your highly complicated plot:

    plot sin(x)
    

    Result: Plot with tics outside and inside the canvas

    This method also allows you to break the axis

  • Drawing axis twice:

    This method is easier; but you need to set set margins of the canvas, and to use the multiplot mode:

    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
    

    The result is similar :)

0
votes

Quick & dirty approach:

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

Beware this overprints your graph with a second one. Should be OK for bitmap output, but don't do it if you have vector output (pdf, eps), especially if your graph is complicated or contains a lot of datapoints. It blows up the resulting file to twice its size.

Gnuplot at the moment (v 5.0pl1) has no option to place the tics centered on the axis. You'll have to use one of the workarounds shown here.