# HG changeset patch
# User Markus Mützel <markus.muetzel@gmx.de>
# Date 1479247815 -3600
#      Tue Nov 15 23:10:15 2016 +0100
# Node ID b54934b5f262ab38aa5c01c839692892d5a74378
# Parent  5b1fdeb1aa04a33c5ab3d467d445a7eabf804ef3
Improve support of "(xy)axislocation" "origin" (bug #48562).

* graphics.[cc,in.h] (calc_ticklabels): Omit tick labels that are
obstructed by axes. Position correctly on logarithmic axes.
* gl-render.cc (opengl_renderer::draw_axes_[xy]_grid): Swap ticks and
labels when origin crosses the middle of the plot. Draw axis at border
if origin is outside of axis limits.

diff -r 5b1fdeb1aa04 -r b54934b5f262 libinterp/corefcn/gl-render.cc
--- a/libinterp/corefcn/gl-render.cc	Tue Nov 15 12:24:44 2016 -0500
+++ b/libinterp/corefcn/gl-render.cc	Tue Nov 15 23:10:15 2016 +0100
@@ -1212,8 +1212,8 @@
     bool xySym = props.get_xySym ();
     bool layer2Dtop = props.get_layer2Dtop ();
     bool is2d = props.get_is2D ();
-    bool isXOrigin = props.xaxislocation_is ("origin");
-    bool isYOrigin = props.yaxislocation_is ("origin");
+    bool isXOrigin = props.xaxislocation_is ("origin") && ! props.yscale_is ("log");
+    bool isYOrigin = props.yaxislocation_is ("origin") && ! props.xscale_is ("log");
     bool boxFull = (props.get_boxstyle () == "full");
     double linewidth = props.get_linewidth ();
     double xPlane = props.get_xPlane ();
@@ -1364,6 +1364,8 @@
         double fz = props.get_fz ();
         double x_min = props.get_x_min ();
         double x_max = props.get_x_max ();
+        double y_min = props.get_y_min ();
+        double y_max = props.get_y_max ();
         double yPlane = props.get_yPlane ();
         double yPlaneN = props.get_yPlaneN ();
         double ypTick = props.get_ypTick ();
@@ -1386,7 +1388,9 @@
         bool do_xminorgrid = (props.is_xminorgrid ()
                               && (minorgridstyle != "none"));
         bool do_xminortick = props.is_xminortick ();
-        bool is_origin = props.xaxislocation_is ("origin") && props.get_is2D ();
+        bool is_origin = props.xaxislocation_is ("origin") && props.get_is2D ()
+                         && ! props.yscale_is ("log");
+        bool is_origin_low = is_origin && (y_min+y_max)<0;
         Matrix xticks = xform.xscale (props.get_xtick ().matrix_value ());
         Matrix xmticks = xform.xscale (props.get_xminortickvalues ().matrix_value ());
         string_vector xticklabels = props.get_xticklabel ().string_vector_value ();
@@ -1432,11 +1436,14 @@
         set_color (props.get_xcolor_rgb ());
 
         // axis line
+        double y_axis_pos = 0.;
         if (is_origin)
           {
+            y_axis_pos = octave::math::max (octave::math::min (0., y_max), y_min);
             glBegin (GL_LINES);
-            glVertex3d (x_min, 0, zpTick);
-            glVertex3d (x_max, 0, zpTick);
+            set_color (props.get_ycolor_rgb ());
+            glVertex3d (x_min, y_axis_pos, zpTick);
+            glVertex3d (x_max, y_axis_pos, zpTick);
             glEnd ();
           }
 
@@ -1445,50 +1452,56 @@
           {
             if (tick_along_z)
               render_tickmarks (xmticks, x_min, x_max,
-                                (is_origin ? 0. : ypTick), ypTick,
+                                is_origin ? y_axis_pos : ypTick, ypTick,
                                 zpTick, zpTickN, 0., 0.,
+                                (is_origin_low ? -1. : 1.) * 
                                 octave::math::signum (zpTick-zpTickN)*fz*xticklen/2,
-                                0, mirror);
+                                0, ! is_origin && mirror);
             else
               render_tickmarks (xmticks, x_min, x_max,
-                                (is_origin ? 0. : ypTick), ypTickN,
+                                is_origin ? y_axis_pos : ypTick, ypTickN,
                                 zpTick, zpTick, 0.,
+                                (is_origin_low ? -1. : 1.) * 
                                 octave::math::signum (ypTick-ypTickN)*fy*xticklen/2,
-                                0., 0, mirror);
+                                0., 0, ! is_origin && mirror);
           }
 
         // tick marks
         if (tick_along_z)
-          {
-            render_tickmarks (xticks, x_min, x_max,
-                              (is_origin ? 0. : ypTick), ypTick,
-                              zpTick, zpTickN, 0., 0.,
-                              octave::math::signum (zpTick-zpTickN)*fz*xticklen,
-                              0, mirror);
-          }
+          render_tickmarks (xticks, x_min, x_max,
+                            is_origin ? y_axis_pos : ypTick, ypTick,
+                            zpTick, zpTickN, 0., 0.,
+                            (is_origin_low ? -1. : 1.) * 
+                            octave::math::signum (zpTick-zpTickN)*fz*xticklen,
+                            0, ! is_origin && mirror);
         else
-          {
-            render_tickmarks (xticks, x_min, x_max,
-                              (is_origin ? 0. : ypTick), ypTickN,
-                              zpTick, zpTick, 0.,
-                              octave::math::signum (ypTick-ypTickN)*fy*xticklen,
-                              0., 0, mirror);
-          }
+          render_tickmarks (xticks, x_min, x_max,
+                            is_origin ? y_axis_pos : ypTick, ypTickN,
+                            zpTick, zpTick, 0.,
+                            (is_origin_low ? -1. : 1.) * 
+                            octave::math::signum (ypTick-ypTickN)*fy*xticklen,
+                            0., 0, ! is_origin && mirror);
 
         // tick texts
         if (xticklabels.numel () > 0)
           {
-            int halign = (xstate == AXE_HORZ_DIR ? 1 : (xyzSym ? 0 : 2));
-            int valign = (xstate == AXE_VERT_DIR ? 1 : (x2Dtop ? 0 : 2));
+            int halign = (xstate == AXE_HORZ_DIR ? 1 :
+                          (xyzSym || is_origin_low ? 0 : 2));
+            int valign = (xstate == AXE_VERT_DIR ? 1 :
+                          (x2Dtop || is_origin_low ? 0 : 2));
 
             if (tick_along_z)
               render_ticktexts (xticks, xticklabels, x_min, x_max,
-                                (is_origin ? 0. : ypTick),
-                                zpTick+octave::math::signum (zpTick-zpTickN)*fz*xtickoffset,
+                                is_origin ? y_axis_pos : ypTick,
+                                zpTick +
+                                (is_origin_low ? -1. : 1.) * 
+                                octave::math::signum (zpTick-zpTickN)*fz*xtickoffset,
                                 0, halign, valign, wmax, hmax);
             else
               render_ticktexts (xticks, xticklabels, x_min, x_max,
-                                (is_origin ? 0. : ypTick) + octave::math::signum (ypTick-ypTickN)*fy*xtickoffset,
+                                (is_origin ? y_axis_pos : ypTick) +
+                                (is_origin_low ?  -1. : 1.) *
+                                octave::math::signum (ypTick-ypTickN)*fy*xtickoffset,
                                 zpTick, 0, halign, valign, wmax, hmax);
           }
 
@@ -1533,6 +1546,8 @@
         double xpTickN = props.get_xpTickN ();
         double y_min = props.get_y_min ();
         double y_max = props.get_y_max ();
+        double x_min = props.get_x_min ();
+        double x_max = props.get_x_max ();
         double zPlane = props.get_zPlane ();
         double zPlaneN = props.get_zPlaneN ();
         double zpTick = props.get_zpTick ();
@@ -1551,7 +1566,9 @@
         bool do_yminorgrid = (props.is_yminorgrid ()
                               && (minorgridstyle != "none"));
         bool do_yminortick = props.is_yminortick ();
-        bool is_origin = props.yaxislocation_is ("origin") && props.get_is2D ();
+        bool is_origin = props.yaxislocation_is ("origin") && props.get_is2D ()
+                         && ! props.xscale_is ("log");
+        bool is_origin_low = is_origin && (x_min+x_max)<0;
         Matrix yticks = xform.yscale (props.get_ytick ().matrix_value ());
         Matrix ymticks = xform.yscale (props.get_yminortickvalues ().matrix_value ());
         string_vector yticklabels = props.get_yticklabel ().string_vector_value ();
@@ -1598,11 +1615,14 @@
         set_color (props.get_ycolor_rgb ());
 
         // axis line
+        double x_axis_pos = 0.;
         if (is_origin)
           {
+            x_axis_pos = octave::math::max (octave::math::min (0., x_max), x_min);
             glBegin (GL_LINES);
-            glVertex3d (0., y_min, zpTick);
-            glVertex3d (0., y_max, zpTick);
+            set_color (props.get_ycolor_rgb ());
+            glVertex3d (x_axis_pos, y_min, zpTick);
+            glVertex3d (x_axis_pos, y_max, zpTick);
             glEnd ();
           }
 
@@ -1611,47 +1631,55 @@
           {
             if (tick_along_z)
               render_tickmarks (ymticks, y_min, y_max,
-                                (is_origin ? 0. : xpTick), xpTick,
+                                is_origin ? x_axis_pos : xpTick, xpTick,
                                 zpTick, zpTickN, 0., 0.,
+                                (is_origin_low ? -1. : 1.) * 
                                 octave::math::signum (zpTick-zpTickN)*fz*yticklen/2,
-                                1, mirror);
+                                1, ! is_origin && mirror);
             else
               render_tickmarks (ymticks, y_min, y_max,
-                                (is_origin ? 0. : xpTick), xpTickN,
+                                is_origin ? x_axis_pos : xpTick, xpTickN,
                                 zpTick, zpTick,
+                                (is_origin_low ? -1. : 1.) * 
                                 octave::math::signum (xpTick-xpTickN)*fx*yticklen/2,
-                                0., 0., 1, mirror);
+                                0., 0., 1, ! is_origin && mirror);
           }
 
         // tick marks
         if (tick_along_z)
           render_tickmarks (yticks, y_min, y_max,
-                            (is_origin ? 0. : xpTick), xpTick,
+                            is_origin ? x_axis_pos : xpTick, xpTick,
                             zpTick, zpTickN, 0., 0.,
+                            (is_origin_low ? -1. : 1.) * 
                             octave::math::signum (zpTick-zpTickN)*fz*yticklen,
-                            1, mirror);
+                            1, ! is_origin && mirror);
         else
           render_tickmarks (yticks, y_min, y_max,
-                            (is_origin ? 0. : xpTick), xpTickN,
+                            is_origin ? x_axis_pos : xpTick, xpTickN,
                             zpTick, zpTick,
+                            (is_origin_low ? -1. : 1.) * 
                             octave::math::signum (xPlaneN-xPlane)*fx*yticklen,
-                            0., 0., 1, mirror);
+                            0., 0., 1, ! is_origin && mirror);
 
         // tick texts
         if (yticklabels.numel () > 0)
           {
-            int halign = (ystate == AXE_HORZ_DIR
-                          ? 1 : (! xyzSym || y2Dright ? 0 : 2));
-            int valign = (ystate == AXE_VERT_DIR ? 1 : 2);
+            int halign = (ystate == AXE_HORZ_DIR ? 1 :
+                          (! xyzSym || y2Dright || is_origin_low ? 0 : 2));
+            int valign = (ystate == AXE_VERT_DIR ? 1 : (is_origin_low ? 0 : 2));
 
             if (tick_along_z)
               render_ticktexts (yticks, yticklabels, y_min, y_max,
-                                (is_origin ? 0. : xpTick),
-                                zpTick+octave::math::signum (zpTick-zpTickN)*fz*ytickoffset,
+                                is_origin ? x_axis_pos : xpTick,
+                                zpTick +
+                                (is_origin_low ? -1. : 1.) * 
+                                octave::math::signum (zpTick-zpTickN)*fz*ytickoffset,
                                 1, halign, valign, wmax, hmax);
             else
               render_ticktexts (yticks, yticklabels, y_min, y_max,
-                                (is_origin ? 0. : xpTick) + octave::math::signum (xpTick-xpTickN)*fx*ytickoffset,
+                                (is_origin ? x_axis_pos : xpTick) +
+                                (is_origin_low ?  -1. : 1.) *
+                                octave::math::signum (xpTick-xpTickN)*fx*ytickoffset,
                                 zpTick, 1, halign, valign, wmax, hmax);
           }
 
diff -r 5b1fdeb1aa04 -r b54934b5f262 libinterp/corefcn/graphics.cc
--- a/libinterp/corefcn/graphics.cc	Tue Nov 15 12:24:44 2016 -0500
+++ b/libinterp/corefcn/graphics.cc	Tue Nov 15 23:10:15 2016 +0100
@@ -4517,9 +4517,13 @@
   sy = "linear";
   sz = "linear";
 
-  calc_ticklabels (xtick, xticklabel, xscale.is ("log"));
-  calc_ticklabels (ytick, yticklabel, yscale.is ("log"));
-  calc_ticklabels (ztick, zticklabel, zscale.is ("log"));
+  calc_ticklabels (xtick, xticklabel, xscale.is ("log"), xaxislocation_is ("origin"),
+                   yscale.is ("log") ? 2 : (yaxislocation_is ("origin") ? 0 :
+                   (yaxislocation_is ("left") ? -1 : 1)), xlim);
+  calc_ticklabels (ytick, yticklabel, yscale.is ("log"), yaxislocation_is ("origin"),
+                   xscale.is ("log") ? 2 : (xaxislocation_is ("origin") ? 0 :
+                   (xaxislocation_is ("bottom") ? -1 : 1)), ylim);
+  calc_ticklabels (ztick, zticklabel, zscale.is ("log"), false, 2, zlim);
 
   xset (xlabel.handle_value (), "handlevisibility", "off");
   xset (ylabel.handle_value (), "handlevisibility", "off");
@@ -5599,14 +5603,18 @@
   layer2Dtop = false;
   if (xstate == AXE_HORZ_DIR && ystate == AXE_VERT_DIR)
     {
-      if (xaxislocation_is ("top"))
+      Matrix ylimits = get_ylim ().matrix_value ();
+      if (xaxislocation_is ("top") ||
+          (yscale_is ("log") && xaxislocation_is ("origin") && (ylimits(1) < 0.)))
         {
           std::swap (yPlane, yPlaneN);
           x2Dtop = true;
         }
       ypTick = yPlaneN;
       ypTickN = yPlane;
-      if (yaxislocation_is ("right"))
+      Matrix xlimits = get_xlim ().matrix_value ();
+      if (yaxislocation_is ("right") || 
+          (xscale_is ("log") && yaxislocation_is ("origin") && (xlimits(1) < 0.)))
         {
           std::swap (xPlane, xPlaneN);
           y2Dright = true;
@@ -7022,12 +7030,35 @@
 
 void
 axes::properties::calc_ticklabels (const array_property& ticks,
-                                   any_property& labels, bool logscale)
+                                   any_property& labels, bool logscale,
+                                   const bool is_origin,
+                                   const int other_axislocation,
+                                   const array_property& axis_lims)
 {
   Matrix values = ticks.get ().matrix_value ();
+  Matrix lims = axis_lims.get ().matrix_value ();
   Cell c (values.dims ());
   std::ostringstream os;
 
+  // omit tick labels depending on location of other axis
+  ColumnVector omit_ticks (3, octave::numeric_limits<double>::NaN ());
+  if (get_is2D () && is_origin)
+    {
+      if (other_axislocation == 0)
+        {
+          omit_ticks(0) = octave::math::max (octave::math::min (0., lims(1)), lims(0));
+        }
+      else if (other_axislocation == 1)
+        omit_ticks(0) = lims(1);
+      else if (other_axislocation == -1)
+        omit_ticks(0) = lims(0);
+      if (is_box ())
+        {
+          omit_ticks(1) = lims(0);
+          omit_ticks(2) = lims(1);
+        }
+    }
+
   if (logscale)
     {
       double significand;
@@ -7044,6 +7075,16 @@
 
       for (int i = 0; i < values.numel (); i++)
         {
+          bool omit_tick = false;
+          for (int i_omit = 0; i_omit < omit_ticks.numel (); i_omit++)
+            if (values(i) == omit_ticks(i_omit))
+              omit_tick = true;
+          if (omit_tick)
+            {
+              c(i) = "";
+              continue;
+            }
+
           if (values(i) < 0.0)
             exponent = std::floor (std::log10 (-values(i)));
           else
@@ -7074,9 +7115,18 @@
     {
       for (int i = 0; i < values.numel (); i++)
         {
-          os.str ("");
-          os << values(i);
-          c(i) = os.str ();
+          bool omit_tick = false;
+          for (int i_omit = 0; i_omit < omit_ticks.numel (); i_omit++)
+            if (values(i) == omit_ticks(i_omit))
+              omit_tick = true;
+          if (omit_tick)
+            c(i) = "";
+          else
+            {
+              os.str ("");
+              os << values(i);
+              c(i) = os.str ();
+            }
         }
     }
 
diff -r 5b1fdeb1aa04 -r b54934b5f262 libinterp/corefcn/graphics.in.h
--- a/libinterp/corefcn/graphics.in.h	Tue Nov 15 12:24:44 2016 -0500
+++ b/libinterp/corefcn/graphics.in.h	Tue Nov 15 23:10:15 2016 +0100
@@ -3812,7 +3812,7 @@
       row_vector_property alim m , default_lim ()
       radio_property alimmode , "{auto}|manual"
       color_property ambientlightcolor , color_values (1, 1, 1)
-      bool_property box , "off"
+      bool_property box u , "off"
       radio_property boxstyle , "{back}|full"
       array_property cameraposition m , Matrix (1, 3, 0.0)
       radio_property camerapositionmode , "{auto}|manual"
@@ -3982,6 +3982,15 @@
     void update_plotboxaspectratiomode (void) { sync_positions (); }
 
     void update_layer (void) { update_axes_layout (); }
+    void update_box (void)
+    {
+      calc_ticklabels (xtick, xticklabel, xscale.is ("log"), xaxislocation_is ("origin"),
+                   yscale.is ("log") ? 2 : (yaxislocation_is ("origin") ? 0 :
+                   (yaxislocation_is ("left") ? -1 : 1)), xlim);
+      calc_ticklabels (ytick, yticklabel, yscale.is ("log"), yaxislocation_is ("origin"),
+                   xscale.is ("log") ? 2 : (xaxislocation_is ("origin") ? 0 :
+                   (xaxislocation_is ("bottom") ? -1 : 1)), ylim);
+    }
     void update_yaxislocation (void)
     {
       // FIXME: Remove warning with "zero" in 4.6
@@ -3991,6 +4000,12 @@
                          "set to 'origin' instead.");
       sync_positions ();
       update_axes_layout ();
+      calc_ticklabels (xtick, xticklabel, xscale.is ("log"), xaxislocation_is ("origin"),
+                   yscale.is ("log") ? 2 : (yaxislocation_is ("origin") ? 0 :
+                   (yaxislocation_is ("left") ? -1 : 1)), xlim);
+      calc_ticklabels (ytick, yticklabel, yscale.is ("log"), yaxislocation_is ("origin"),
+                   xscale.is ("log") ? 2 : (xaxislocation_is ("origin") ? 0 :
+                   (xaxislocation_is ("bottom") ? -1 : 1)), ylim);
       update_ylabel_position ();
     }
     void update_xaxislocation (void)
@@ -4002,6 +4017,12 @@
                          "set to 'origin' instead.");
       sync_positions ();
       update_axes_layout ();
+      calc_ticklabels (xtick, xticklabel, xscale.is ("log"), xaxislocation_is ("origin"),
+                       yscale.is ("log") ? 2 : (yaxislocation_is ("origin") ? 0 :
+                       (yaxislocation_is ("left") ? -1 : 1)), xlim);
+      calc_ticklabels (ytick, yticklabel, yscale.is ("log"), yaxislocation_is ("origin"),
+                       xscale.is ("log") ? 2 : (xaxislocation_is ("origin") ? 0 :
+                       (xaxislocation_is ("bottom") ? -1 : 1)), ylim);
       update_xlabel_position ();
     }
 
@@ -4018,7 +4039,9 @@
       calc_ticks_and_lims (xlim, xtick, xminortickvalues, xlimmode.is ("auto"),
                            xtickmode.is ("auto"), xscale.is ("log"));
       if (xticklabelmode.is ("auto"))
-        calc_ticklabels (xtick, xticklabel, xscale.is ("log"));
+        calc_ticklabels (xtick, xticklabel, xscale.is ("log"), xaxislocation_is ("origin"),
+                         yscale.is ("log") ? 2 : (yaxislocation_is ("origin") ? 0 :
+                         (yaxislocation_is ("left") ? -1 : 1)), xlim);
       sync_positions ();
     }
     void update_ytick (void)
@@ -4026,7 +4049,9 @@
       calc_ticks_and_lims (ylim, ytick, yminortickvalues, ylimmode.is ("auto"),
                            ytickmode.is ("auto"), yscale.is ("log"));
       if (yticklabelmode.is ("auto"))
-        calc_ticklabels (ytick, yticklabel, yscale.is ("log"));
+        calc_ticklabels (ytick, yticklabel, yscale.is ("log"), yaxislocation_is ("origin"),
+                         xscale.is ("log") ? 2 : (xaxislocation_is ("origin") ? 0 :
+                         (xaxislocation_is ("bottom") ? -1 : 1)), ylim);
       sync_positions ();
     }
     void update_ztick (void)
@@ -4034,7 +4059,7 @@
       calc_ticks_and_lims (zlim, ztick, zminortickvalues, zlimmode.is ("auto"),
                            ztickmode.is ("auto"), zscale.is ("log"));
       if (zticklabelmode.is ("auto"))
-        calc_ticklabels (ztick, zticklabel, zscale.is ("log"));
+        calc_ticklabels (ztick, zticklabel, zscale.is ("log"), false, 2, zlim);
       sync_positions ();
     }
 
@@ -4057,17 +4082,21 @@
     void update_xticklabelmode (void)
     {
       if (xticklabelmode.is ("auto"))
-        calc_ticklabels (xtick, xticklabel, xscale.is ("log"));
+        calc_ticklabels (xtick, xticklabel, xscale.is ("log"), xaxislocation_is ("origin"),
+                         yscale.is ("log") ? 2 : (yaxislocation_is ("origin") ? 0 :
+                         (yaxislocation_is ("left") ? -1 : 1)), xlim);
     }
     void update_yticklabelmode (void)
     {
       if (yticklabelmode.is ("auto"))
-        calc_ticklabels (ytick, yticklabel, yscale.is ("log"));
+        calc_ticklabels (ytick, yticklabel, yscale.is ("log"), yaxislocation_is ("origin"),
+                         xscale.is ("log") ? 2 : (xaxislocation_is ("origin") ? 0 :
+                         (xaxislocation_is ("bottom") ? -1 : 1)), ylim);
     }
     void update_zticklabelmode (void)
     {
       if (zticklabelmode.is ("auto"))
-        calc_ticklabels (ztick, zticklabel, zscale.is ("log"));
+        calc_ticklabels (ztick, zticklabel, zscale.is ("log"), false, 2, zlim);
     }
 
     void update_font (std::string prop = "");
@@ -4195,7 +4224,9 @@
                               array_property& mticks, bool limmode_is_auto,
                               bool tickmode_is_auto, bool is_logscale);
     void calc_ticklabels (const array_property& ticks, any_property& labels,
-                          bool is_logscale);
+                          bool is_logscale, const bool is_origin,
+                          const int other_axislocation,
+                          const array_property& axis_lims);
     Matrix get_ticklabel_extents (const Matrix& ticks,
                                   const string_vector& ticklabels,
                                   const Matrix& limits);
@@ -4232,7 +4263,9 @@
       calc_ticks_and_lims (xlim, xtick, xminortickvalues, xlimmode.is ("auto"),
                            xtickmode.is ("auto"), xscale.is ("log"));
       if (xticklabelmode.is ("auto"))
-        calc_ticklabels (xtick, xticklabel, xscale.is ("log"));
+        calc_ticklabels (xtick, xticklabel, xscale.is ("log"), xaxislocation.is ("origin"),
+                         yscale.is ("log") ? 2 : (yaxislocation_is ("origin") ? 0 :
+                         (yaxislocation_is ("left") ? -1 : 1)), xlim);
 
       fix_limits (xlim);
 
@@ -4246,7 +4279,9 @@
       calc_ticks_and_lims (ylim, ytick, yminortickvalues, ylimmode.is ("auto"),
                            ytickmode.is ("auto"), yscale.is ("log"));
       if (yticklabelmode.is ("auto"))
-        calc_ticklabels (ytick, yticklabel, yscale.is ("log"));
+        calc_ticklabels (ytick, yticklabel, yscale.is ("log"), yaxislocation_is ("origin"),
+                         xscale.is ("log") ? 2 : (xaxislocation_is ("origin") ? 0 :
+                         (xaxislocation_is ("bottom") ? -1 : 1)), ylim);
 
       fix_limits (ylim);
 
@@ -4260,7 +4295,7 @@
       calc_ticks_and_lims (zlim, ztick, zminortickvalues, zlimmode.is ("auto"),
                            ztickmode.is ("auto"), zscale.is ("log"));
       if (zticklabelmode.is ("auto"))
-        calc_ticklabels (ztick, zticklabel, zscale.is ("log"));
+        calc_ticklabels (ztick, zticklabel, zscale.is ("log"), false, 2, zlim);
 
       fix_limits (zlim);
 
