title: gnuplot: draw grid behind plot points and tics in front
body: <p>I am having difficulties with getting the grid lines drawn behind my graph and keeping the axis tic marks in front of them, if the data points are near the axis. </p>
  
  <p>Consider these example data, named "t_data": </p>
  
  <pre><code>   0   1
     1   3
     1.8 0
     3   5
     4   0
     5   2
  </code></pre>
  
  <p>and this script: </p>
  
  <pre><code>reset session
  
  set terminal pdfcairo enhanced color font "Arial,10" size 7.5cm,6cm
  
  set output "t_graph.pdf"
  
  set style line 1 lc rgb "#ff0000" lw 1 pt 5 ps 0.5 pi -1
  set pointintervalbox 0.7
  
  unset key
  unset title
  unset border
  
  set border 3
  set xrange [0:5]
  set yrange [0:*]
  
  set xtics border nomirror out font "Arial,9"
  set ytics border nomirror out font "Arial,9"
  
  set mxtics 5
  set mytics 5
  
  set xlabel "x"
  set ylabel "y"
  
  set grid xtics mxtics ytics back lt -1 lw 1 lc rgb "#808080", lt -1 lw 1 lc rgb "#808080" dt 2
  set tics front
  
  plot "t_data" u 1:2 w lp ls 1
  
  set out
  </code></pre>
  
  <p>In order to get the tic marks to be in front of the data points at <code>x=0, 2</code> and <code>4</code>, I read, e.g., here (<a href="https://stackoverflow.com/questions/21193547/gnuplot-fill-area-curve-keeping-tics-on-top">gnuplot: fill area curve keeping tics on top</a>) that the <code>set tics front</code> command should come before the <code>plot</code> command, as seen in the script. This however seems to override the option <code>back</code> I gave for the <code>set grid</code> command, i.e., the grid is also drawn on top of my graph (it even says <code>Grid drawn at front</code> when I run <code>show grid</code> after executing the script above). </p>
  
  <p>When I interchange the <code>set grid</code> and the <code>set tics</code> commands, both the grid AND the tics are drawn behind the plot points, which thus obscure the major tic marks partly and the minor tic marks fully (note, that the axis is still drawn on top of the plot points in either case). </p>
  
  <p>Can anyone help me, figure out how to get the grid behind the plot points and the tic marks in front of them (I think this way of plotting graphs makes the most sense, but that's really just IMHO)? I'm also really curious as to the origin of why the <code>set tics</code> and <code>set grid</code> commands seemingly influence each other. </p>
  
  <p>I'm using gnuplot version <code>5.0 patchlevel 0</code> on OpenSUSE 42.3 LTS, if that's of importance. </p>