# HG changeset patch
# User Stefan Mahr <dac922@gmx.de>
# Date 1393723653 -3600
#      Sun Mar 02 02:27:33 2014 +0100
# Node ID 4ee907fd94b504d23c4f54b1e51d0409f32494d6
# Parent  9c8321ea6f585749685b0cacab396b2d87104883
fix xticklabel with minor grid (bug #38139, bug #40256)
* scripts/plot/util/private/__go_draw_axes__.m (do_tics_1):
  Set manual ticks first and add manual labels later.
  Use variable mirror as string to avoid code duplication.
  Set mtics at the end to avoid code duplication.

diff -r 9c8321ea6f58 -r 4ee907fd94b5 scripts/plot/util/private/__go_draw_axes__.m
--- a/scripts/plot/util/private/__go_draw_axes__.m	Thu Feb 27 09:56:47 2014 -0800
+++ b/scripts/plot/util/private/__go_draw_axes__.m	Sun Mar 02 02:27:33 2014 +0100
@@ -2114,6 +2114,11 @@
                     plot_stream, mirror, mono, axispos, tickdir, ticklength,
                     fontname, fontspec, interpreter, scale, sgn, gnuplot_term)
   persistent warned_latex = false;
+  if (mirror)
+    mirror = "mirror";
+  else
+    mirror = "nomirror";
+  end
   if (strcmpi (interpreter, "tex"))
     for n = 1 : numel (labels)
       labels{n} = __tex2enhanced__ (labels{n}, fontname, false, false);
@@ -2142,7 +2147,16 @@
   if (strcmpi (ticmode, "manual") || strcmpi (labelmode, "manual"))
     if (isempty (tics))
       fprintf (plot_stream, "unset %stics;\nunset m%stics;\n", ax, ax);
-    elseif (strcmpi (labelmode, "manual"))
+      return
+    endif
+    if (strcmpi (ticmode, "manual"))
+      fprintf (plot_stream, "set format %s \"%s\";\n", ax, fmt);
+      fprintf (plot_stream, "set %stics %s %s %s %s (", ax, tickdir,
+               ticklength, axispos, mirror);
+      fprintf (plot_stream, " %.15g,", tics(1:end-1));
+      fprintf (plot_stream, " %.15g) %s;\n", tics(end), fontspec);
+    endif
+    if (strcmpi (labelmode, "manual"))
       if (ischar (labels))
         labels = cellstr (labels);
       endif
@@ -2156,15 +2170,8 @@
         k = 1;
         ntics = numel (tics);
         nlabels = numel (labels);
-        fprintf (plot_stream, "set format %s \"%%g\";\n", ax);
-        if (mirror)
-          fprintf (plot_stream, "set %stics %s %s %s mirror (", ax,
-                   tickdir, ticklength, axispos);
-        else
-          fprintf (plot_stream, "set %stics %s %s %s nomirror (", ax,
-                   tickdir, ticklength, axispos);
-        endif
-
+        fprintf (plot_stream, "set %stics add %s %s %s %s (", ax,
+                 tickdir, ticklength, axispos, mirror);
         labels = regexprep (labels, '%', "%%");
         for i = 1:ntics
           fprintf (plot_stream, " \"%s\" %.15g", labels{k++}, tics(i));
@@ -2176,45 +2183,19 @@
           endif
         endfor
         fprintf (plot_stream, ") %s %s;\n", colorspec, fontspec);
-        if (strcmp (mtics, "on"))
-          fprintf (plot_stream, "set m%stics %d;\n", ax, num_mtics);
-        else
-          fprintf (plot_stream, "unset m%stics;\n", ax);
-        endif
       else
         error ("__go_draw_axes__: unsupported type of ticklabel");
       endif
-    else
-      fprintf (plot_stream, "set format %s \"%s\";\n", ax, fmt);
-      if (mirror)
-        fprintf (plot_stream, "set %stics %s %s %s mirror (", ax, tickdir,
-                 ticklength, axispos);
-      else
-        fprintf (plot_stream, "set %stics %s %s %s nomirror (", ax, tickdir,
-                 ticklength, axispos);
-      endif
-      fprintf (plot_stream, " %.15g,", tics(1:end-1));
-      fprintf (plot_stream, " %.15g) %s;\n", tics(end), fontspec);
-      if (strcmp (mtics, "on"))
-        fprintf (plot_stream, "set m%stics %d;\n", ax, num_mtics);
-      else
-        fprintf (plot_stream, "unset m%stics;\n", ax);
-      endif
     endif
   else
     fprintf (plot_stream, "set format %s \"%s\";\n", ax, fmt);
-    if (mirror)
-      fprintf (plot_stream, "set %stics %s %s %s mirror %s %s;\n", ax,
-               axispos, tickdir, ticklength, colorspec, fontspec);
-    else
-      fprintf (plot_stream, "set %stics %s %s %s nomirror %s %s;\n", ax,
-               tickdir, ticklength, axispos, colorspec, fontspec);
-    endif
-    if (strcmp (mtics, "on"))
-      fprintf (plot_stream, "set m%stics %d;\n", ax, num_mtics);
-    else
-      fprintf (plot_stream, "unset m%stics;\n", ax);
-    endif
+    fprintf (plot_stream, "set %stics %s %s %s %s %s %s;\n", ax,
+             tickdir, ticklength, axispos, mirror, colorspec, fontspec);
+  endif
+  if (strcmp (mtics, "on"))
+    fprintf (plot_stream, "set m%stics %d;\n", ax, num_mtics);
+  else
+    fprintf (plot_stream, "unset m%stics;\n", ax);
   endif
 endfunction
 
