octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Changeset] plotyy leaves traces of previous plots


From: David Bateman
Subject: Re: [Changeset] plotyy leaves traces of previous plots
Date: Mon, 31 Mar 2008 11:56:42 +0200
User-agent: Thunderbird 2.0.0.12 (X11/20080306)

John W. Eaton wrote:
> On 28-Mar-2008, Bateman David-ADB014 wrote:
>
> | Shai, Micheal,
> | 
> | John suggested I should direct a question at you and the rest of the 
> maintainers list but what is the expected behavior of newplot in the case of 
> plotyy and what is the correct means to detect that an axes forms part of a 
> set of axes in a plotyy figure. The details of the conversation are below. 
> John I don't have easy access to the patch I sent to newplot for discussion, 
> so could you forward it?
> | 
>
> Here it is.
>
> jwe
>
>
>   
Here is an updated version (replaces the previous version) that also
fixes the issue of spurious tick marks in plotyy (Thanks Petr for the
help), and addresses the fact that the newplot change I proposed results
in the second axis of the plotyy being deleted and so the plotyy
function can't assume at any point that because an axis existed at the
start of the call it exists later on. This allows repeated calls the
plotyy to work correctly.

The remain issue is whether the manner to detect that the current axis
handle points to one of a plotyy set of axes handles is correct. I used
the activepositionproperty of the axis to do this, but I'm not sure this
is valid. So I'd appreciate feedback from Michael or Shai if you have
some advice on this point..

Regards
David

-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary

# HG changeset patch
# User David Bateman <address@hidden>
# Date 1206957093 -7200
# Node ID efe5a3879e7d947545d14fd5233ac382c546fc0f
# Parent  9c4e5029bede5020bd6d7f633f6b545f6dcf091c
Treat plotyy in newplot, fix spurious tics for plotyy with gnuplot backend and 
more care in the treatment of the axes is plotyy.

diff --git a/scripts/ChangeLog b/scripts/ChangeLog
--- a/scripts/ChangeLog
+++ b/scripts/ChangeLog
@@ -1,3 +1,12 @@ 2008-03-27  Jaroslav Hajek  <address@hidden
+2008-03-31  David Bateman  <address@hidden>
+
+       * plot/newplot.m: Treat the case of plotyy.
+       * plot/__go_draw_axes__.m: Set the tick direction in the main call
+       the set tics rather than separately to avoid issues with multiple
+       ticks in plotyy.
+       * plot/plotyy.m: Don't assume that an axis exists before setting
+       it. Check and if it doesn't exist create it.
+       
 2008-03-27  Jaroslav Hajek  <address@hidden>
 
        * general/lookup.m: Remove (lookup moved to DLD-FUNCTIONS).
diff --git a/scripts/plot/__go_draw_axes__.m b/scripts/plot/__go_draw_axes__.m
--- a/scripts/plot/__go_draw_axes__.m
+++ b/scripts/plot/__go_draw_axes__.m
@@ -1063,21 +1063,27 @@ function __go_draw_axes__ (h, plot_strea
        fputs (plot_stream, "set border 895;\n");
       else
        if (strcmpi (axis_obj.yaxislocation, "right"))
-         fputs (plot_stream, "unset ytics; set y2tics nomirror\n");
+         fputs (plot_stream, "unset ytics; set y2tics %s nomirror\n",
+                axis_obj.tickdir);
          if (strcmpi (axis_obj.xaxislocation, "top"))
-           fputs (plot_stream, "unset xtics; set x2tics nomirror\n");
+           fputs (plot_stream, "unset xtics; set x2tics %s nomirror\n",
+                axis_obj.tickdir);
            fputs (plot_stream, "set border 12;\n");
          else
-           fputs (plot_stream, "unset x2tics; set xtics nomirror\n");
+           fputs (plot_stream, "unset x2tics; set xtics %s nomirror\n",
+                axis_obj.tickdir);
            fputs (plot_stream, "set border 9;\n");
          endif
        else
-         fputs (plot_stream, "unset y2tics; set ytics nomirror\n");
+         fputs (plot_stream, "unset y2tics; set ytics %s nomirror\n",
+                axis_obj.tickdir);
          if (strcmpi (axis_obj.xaxislocation, "top"))
-           fputs (plot_stream, "unset xtics; set x2tics nomirror\n");
+           fputs (plot_stream, "unset xtics; set x2tics %s nomirror\n",
+                  axis_obj.tickdir);
            fputs (plot_stream, "set border 6;\n");
          else
-           fputs (plot_stream, "unset x2tics; set xtics nomirror\n");
+           fputs (plot_stream, "unset x2tics; set xtics %s nomirror\n",
+                  axis_obj.tickdir);
            fputs (plot_stream, "set border 3;\n");
          endif
        endif
@@ -1088,7 +1094,6 @@ function __go_draw_axes__ (h, plot_strea
       fputs (plot_stream, "unset border; unset tics\n");
     else
       fprintf (plot_stream, "set border lw %f;\n", axis_obj.linewidth);
-      fprintf (plot_stream, "set tics %s\n", axis_obj.tickdir);
     endif
 
     if (strcmpi (axis_obj.key, "on"))
@@ -1471,42 +1476,49 @@ function do_tics (obj, plot_stream, ymir
 function do_tics (obj, plot_stream, ymirror, mono)
   if (strcmpi (obj.xaxislocation, "top"))
     do_tics_1 (obj.xtickmode, obj.xtick, obj.xticklabelmode, obj.xticklabel,
-              obj.xcolor, "x2", plot_stream, true, mono, "border");
+              obj.xcolor, "x2", plot_stream, true, mono, "border",
+              obj.tickdir);
     do_tics_1 ("manual", [], obj.xticklabelmode, obj.xticklabel,
-              obj.xcolor, "x", plot_stream, true, mono, "border");
+              obj.xcolor, "x", plot_stream, true, mono, "border", "");
   elseif (strcmpi (obj.xaxislocation, "zero"))
     do_tics_1 (obj.xtickmode, obj.xtick, obj.xticklabelmode, obj.xticklabel,
-              obj.xcolor, "x", plot_stream, true, mono, "axis");
+              obj.xcolor, "x", plot_stream, true, mono, "axis",
+              obj.tickdir);
     do_tics_1 ("manual", [], obj.xticklabelmode, obj.xticklabel,
-              obj.xcolor, "x2", plot_stream, true, mono, "axis");
+              obj.xcolor, "x2", plot_stream, true, mono, "axis", "");
   else
     do_tics_1 (obj.xtickmode, obj.xtick, obj.xticklabelmode, obj.xticklabel,
-              obj.xcolor, "x", plot_stream, true, mono, "border");
+              obj.xcolor, "x", plot_stream, true, mono, "border",
+              obj.tickdir);
     do_tics_1 ("manual", [], obj.xticklabelmode, obj.xticklabel,
-              obj.xcolor, "x2", plot_stream, true, mono, "border");
+              obj.xcolor, "x2", plot_stream, true, mono, "border", "");
   endif
   if (strcmpi (obj.yaxislocation, "right"))
     do_tics_1 (obj.ytickmode, obj.ytick, obj.yticklabelmode, obj.yticklabel,
-              obj.ycolor, "y2", plot_stream, ymirror, mono, "border");
+              obj.ycolor, "y2", plot_stream, ymirror, mono, "border",
+              obj.tickdir);
     do_tics_1 ("manual", [], obj.yticklabelmode, obj.yticklabel,
-              obj.ycolor, "y", plot_stream, ymirror, mono, "border");
+              obj.ycolor, "y", plot_stream, ymirror, mono, "border", "");
   elseif (strcmpi (obj.xaxislocation, "zero"))
     do_tics_1 (obj.ytickmode, obj.ytick, obj.yticklabelmode, obj.yticklabel,
-              obj.ycolor, "y", plot_stream, ymirror, mono, "axis");
+              obj.ycolor, "y", plot_stream, ymirror, mono, "axis",
+              obj.tickdir);
     do_tics_1 ("manual", [], obj.yticklabelmode, obj.yticklabel,
-              obj.ycolor, "y2", plot_stream, ymirror, mono, "axis");
+              obj.ycolor, "y2", plot_stream, ymirror, mono, "axis", "");
   else
     do_tics_1 (obj.ytickmode, obj.ytick, obj.yticklabelmode, obj.yticklabel,
-              obj.ycolor, "y", plot_stream, ymirror, mono, "border");
+              obj.ycolor, "y", plot_stream, ymirror, mono, "border",
+              obj.tickdir);
     do_tics_1 ("manual", [], obj.yticklabelmode, obj.yticklabel,
-              obj.ycolor, "y2", plot_stream, ymirror, mono, "border");
+              obj.ycolor, "y2", plot_stream, ymirror, mono, "border", "");
   endif
   do_tics_1 (obj.ztickmode, obj.ztick, obj.zticklabelmode, obj.zticklabel,
-            obj.zcolor, "z", plot_stream, true, mono, "border");
+            obj.zcolor, "z", plot_stream, true, mono, "border",
+            obj.tickdir);
 endfunction
 
 function do_tics_1 (ticmode, tics, labelmode, labels, color, ax,
-                   plot_stream, mirror, mono, axispos)
+                   plot_stream, mirror, mono, axispos, tickdir)
   colorspec = get_text_colorspec (color, mono);
   if (strcmpi (ticmode, "manual"))
     if (isempty (tics))
@@ -1521,9 +1533,10 @@ function do_tics_1 (ticmode, tics, label
        nlabels = numel (labels);
        fprintf (plot_stream, "set format %s \"%%s\";\n", ax);
        if (mirror)
-         fprintf (plot_stream, "set %stics %s (", ax, axispos);
+         fprintf (plot_stream, "set %stics %s %s (", ax, tickdir, axispos);
        else
-         fprintf (plot_stream, "set %stics %s nomirror (", ax, axispos);
+         fprintf (plot_stream, "set %stics %s %s nomirror (", ax,
+                  tickdir, axispos);
        endif
        labels = regexprep(labels, "%", "%%");
        for i = 1:ntics
@@ -1542,9 +1555,10 @@ function do_tics_1 (ticmode, tics, label
     else
       fprintf (plot_stream, "set format %s \"%%g\";\n", ax);
       if (mirror)
-       fprintf (plot_stream, "set %stics %s (", ax, axispos );
+       fprintf (plot_stream, "set %stics %s %s (", ax, tickdir, axispos );
       else
-       fprintf (plot_stream, "set %stics %s nomirror (", ax, axispos);
+       fprintf (plot_stream, "set %stics %s %s nomirror (", ax, tickdir,
+                axispos);
       endif
       fprintf (plot_stream, " %g,", tics(1:end-1));
       fprintf (plot_stream, " %g);\n", tics(end));
@@ -1552,10 +1566,11 @@ function do_tics_1 (ticmode, tics, label
   else
     fprintf (plot_stream, "set format %s \"%%g\";\n", ax);
     if (mirror)
-      fprintf (plot_stream, "set %stics %s %s;\n", ax, axispos, colorspec);
-    else
-      fprintf (plot_stream, "set %stics %s nomirror %s;\n", ax, 
-              axispos, colorspec);
+      fprintf (plot_stream, "set %stics %s %s %s;\n", ax, axispos, tickdir,
+              colorspec);
+    else
+      fprintf (plot_stream, "set %stics %s %s nomirror %s;\n", ax, 
+              tickdir, axispos, colorspec);
     endif
   endif
 endfunction
diff --git a/scripts/plot/newplot.m b/scripts/plot/newplot.m
--- a/scripts/plot/newplot.m
+++ b/scripts/plot/newplot.m
@@ -39,16 +39,38 @@ function newplot ()
        error ("newplot: unrecognized nextplot property for current figure");
     endswitch
     ca = gca ();
-    anp = get (ca, "nextplot");
-    switch (anp)
-      case "add"
-      case "replacechildren"
-      case "replace"
-       __go_axes_init__ (ca, "replace");
-       __request_drawnow__ ();
-      otherwise
-       error ("newplot: unrecognized nextplot property for current axes");
-    endswitch
+    if (strcmpi (get (ca, "activepositionproperty"), "outerposition"))
+      anp = get (ca, "nextplot");
+      switch (anp)
+       case "add"
+       case "replacechildren"
+       case "replace"
+         __go_axes_init__ (ca, "replace");
+         __request_drawnow__ ();
+       otherwise
+         error ("newplot: unrecognized nextplot property for current axes");
+      endswitch
+    else
+      ## This is probably a plotyy axes. Special case to treat both axes
+      child = get (cf, "children");
+      for i = 1 : length (child)
+       nca = child(i);
+       anp = get (nca, "nextplot");
+       switch (anp)
+         case "add"
+         case "replacechildren"
+         case "replace"
+           if (ca == nca)
+             __go_axes_init__ (ca, "replace");
+           else
+             delete (nca);
+           endif
+         otherwise
+           error ("newplot: unrecognized nextplot property for current axes");
+       endswitch
+      endfor
+      __request_drawnow__ ();
+    endif
   else
     print_usage ();
   endif
diff --git a/scripts/plot/plotyy.m b/scripts/plot/plotyy.m
--- a/scripts/plot/plotyy.m
+++ b/scripts/plot/plotyy.m
@@ -77,10 +77,17 @@ function [Ax, H1, H2] = plotyy (varargin
       ax(2) = axes ();
     else
       ax = get (f, "children");
-      for i = 3 : length (ax)
-       delete (ax (i));
-      endfor
-      ax = ax(1:2);
+      if (length (ax) < 1)
+       ax(1) = axes ();
+       ax(2) = axes ();
+      elseif (length (ax) < 1)
+       ax(2) = axes ();
+      else
+       for i = 3 : length (ax)
+         delete (ax (i));
+       endfor
+       ax = ax(1:2);
+      endif
     endif
     if (nargin < 2)
       varargin = {};
@@ -95,7 +102,10 @@ function [Ax, H1, H2] = plotyy (varargin
   unwind_protect
     [ax, h1, h2] = __plotyy__ (ax, varargin{:});
   unwind_protect_cleanup
-    axes (oldh);
+    ## Careful, the previous axis handle might have been deleted
+    if (ishandle (oldh) && strcmp (get (oldh, "type"), "axes"))
+      axes (oldh);
+    endif
   end_unwind_protect
 
   if (nargout > 0)
@@ -119,8 +129,11 @@ function [ax, h1, h2] = __plotyy__ (ax, 
   endif
 
   xlim = [min([x1(:); x2(:)]), max([x1(:); x2(:)])];
-
-  axes (ax(1));
+  if (ishandle (ax(1)) && strcmp (get (ax(1), "type"), "axes"))
+    axes (ax(1));
+  else
+    ax (1) = axes ();
+  endif
   newplot ();
   h1 = feval (fun1, x1, y1);
 
@@ -131,8 +144,11 @@ function [ax, h1, h2] = __plotyy__ (ax, 
 
   cf = gcf ();
   set (cf, "nextplot", "add");
-  axes (ax(2));
-  newplot ();
+  if (ishandle (ax(2)) && strcmp (get (ax(2), "type"), "axes"))
+    axes (ax(2));
+  else
+    ax (2) = axes ();
+  endif
 
   colors = get (ax(1), "colororder");
   set (ax(2), "colororder", [colors(2:end,:); colors(1,:)]);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]