octave-maintainers
[Top][All Lists]
Advanced

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

Re: Patch to add axis position property


From: Peter Gustafson
Subject: Re: Patch to add axis position property
Date: Fri, 10 Aug 2007 12:21:20 -0400
User-agent: Thunderbird 2.0.0.6 (X11/20070806)

John W. Eaton wrote:
> On  9-Aug-2007, John W. Eaton wrote:
> 
> | On  9-Aug-2007, Peter Gustafson wrote:
> | 
> | | What else would impair me from defining these as axes properties, and
> | | working it out that way?
> | 
> | I think the graphics properties need to be compatible with Matlab.
> 
> Sorry, I misunderstood.  I was thinking that you wanted to continue
> keeping them as line properties.  Having them as axes properties is
> the right way to go, but I'm not sure whether it will be easy to make
> that work with gnuplot.  If it is easy to do, then OK.  If it requires
> heroic effort, then I'd say skip it and help us work on graphics
> capabilities that don't depend on gnuplot.
> 
> Also, for all the gnuplot fans out there, please don't misunderstand
> my comments about gnuplot.  I think it is a very useful program, but I
> don't think it is the right tool to use to implement Matlab-compatible
> graphics for Octave.
> 
> jwe

OK guys and gals, another shot.  This patch should enable plotting using
x2 or y2 axes.

I feel like having the axes properties within the axes object is a nice
feature, and it isn't really hard to add.

With regard to gnuplot... well this isn't a heroic effort so far, even
if the plotyy problem is more difficult.

Some notes: For graphic.*, it implements the additional properties as
axes properties.  I apologize for not using radio properties, I didn't
quite figure out how to do that.  (Can you point to an example property
I could duplicate?)

The __go_draw_axes__ patch is much more significant in terms of the
number of lines changed, since I'm passing an axis location for each of
the gnuplot set statements, but I don't think it tears anything up.  The
changes of substance are that the usingclause now specifies an axes, and
the do_tics_1 function is called for each x1,x2,y1,y2 regardless of the
properties.


Pete

2007-08-10  Peter Gustafson  <address@hidden>

        * src/graphics.h, src/graphics.cc: Add axes properties for 
[xy]axislocation.
        * scripts/plot/__go_draw_axes__.m: Add axis position to the 
usingclause, 
        use axis position in each appropriate gnuplot set statement.
        
Index: scripts/plot/__go_draw_axes__.m
===================================================================
RCS file: /cvs/octave/scripts/plot/__go_draw_axes__.m,v
retrieving revision 1.32
diff -c -r1.32 __go_draw_axes__.m
*** scripts/plot/__go_draw_axes__.m     24 Jul 2007 19:02:27 -0000      1.32
--- scripts/plot/__go_draw_axes__.m     10 Aug 2007 15:53:57 -0000
***************
*** 117,132 ****
        endif
      endif
  
      if (strcmpi (axis_obj.xgrid, "on"))
!       fputs (plot_stream, "set grid xtics;\n");
      else
!       fputs (plot_stream, "set grid noxtics;\n");
      endif
  
      if (strcmpi (axis_obj.ygrid, "on"))
!       fputs (plot_stream, "set grid ytics;\n");
      else
!       fputs (plot_stream, "set grid noytics;\n");
      endif
  
      if (strcmpi (axis_obj.zgrid, "on"))
--- 117,147 ----
        endif
      endif
  
+     if (strcmpi(axis_obj.xaxislocation,"top"))
+       xaxisloc="x2";
+       xaxisloc_using="x2";
+     else
+       xaxisloc="x";
+       xaxisloc_using="x1";
+     endif
+     if (strcmpi(axis_obj.yaxislocation,"right"))
+       yaxisloc="y2";
+       yaxisloc_using="y2";
+     else
+       yaxisloc="y";
+       yaxisloc_using="y1";
+     endif
+ 
      if (strcmpi (axis_obj.xgrid, "on"))
!       fputs (plot_stream, sprintf("set grid %stics;\n",xaxisloc));
      else
!       fputs (plot_stream, sprintf("set grid no%stics;\n",xaxisloc));
      endif
  
      if (strcmpi (axis_obj.ygrid, "on"))
!       fputs (plot_stream, sprintf("set grid %stics;\n",yaxisloc));
      else
!       fputs (plot_stream, sprintf("set grid no%stics;\n",yaxisloc));
      endif
  
      if (strcmpi (axis_obj.zgrid, "on"))
***************
*** 136,152 ****
      endif
  
      if (strcmpi (axis_obj.xminorgrid, "on"))
!       fputs (plot_stream, "set mxtics 5;\n");
!       fputs (plot_stream, "set grid mxtics;\n");
      else
!       fputs (plot_stream, "set grid nomxtics;\n");
      endif
  
      if (strcmpi (axis_obj.yminorgrid, "on"))
!       fputs (plot_stream, "set mytics 5;\n");
!       fputs (plot_stream, "set grid mytics;\n");
      else
!       fputs (plot_stream, "set grid nomytics;\n");
      endif
  
      if (strcmpi (axis_obj.zminorgrid, "on"))
--- 151,167 ----
      endif
  
      if (strcmpi (axis_obj.xminorgrid, "on"))
!       fputs (plot_stream, sprintf("set m%stics 5;\n",xaxisloc));
!       fputs (plot_stream, sprintf("set grid m%stics;\n",xaxisloc));
      else
!       fputs (plot_stream, sprintf("set grid nom%stics;\n",xaxisloc));
      endif
  
      if (strcmpi (axis_obj.yminorgrid, "on"))
!       fputs (plot_stream, sprintf("set m%stics 5;\n",yaxisloc));
!       fputs (plot_stream, sprintf("set grid m%stics;\n",yaxisloc));
      else
!       fputs (plot_stream, sprintf("set grid nom%stics;\n",yaxisloc));
      endif
  
      if (strcmpi (axis_obj.zminorgrid, "on"))
***************
*** 160,175 ****
  
      xlogscale = strcmpi (axis_obj.xscale, "log");
      if (xlogscale)
!       fputs (plot_stream, "set logscale x;\n");
      else
!       fputs (plot_stream, "unset logscale x;\n");
      endif
  
      ylogscale = strcmpi (axis_obj.yscale, "log");
      if (ylogscale)
!       fputs (plot_stream, "set logscale y;\n");
      else
!       fputs (plot_stream, "unset logscale y;\n");
      endif
  
      zlogscale = strcmpi (axis_obj.zscale, "log");
--- 175,190 ----
  
      xlogscale = strcmpi (axis_obj.xscale, "log");
      if (xlogscale)
!       fputs (plot_stream, sprintf("set logscale %s;\n",xaxisloc));
      else
!       fputs (plot_stream, sprintf("unset logscale %s;\n",xaxisloc));
      endif
  
      ylogscale = strcmpi (axis_obj.yscale, "log");
      if (ylogscale)
!       fputs (plot_stream, sprintf("set logscale %s;\n",yaxisloc));
      else
!       fputs (plot_stream, sprintf("unset logscale %s;\n",yaxisloc));
      endif
  
      zlogscale = strcmpi (axis_obj.zscale, "log");
***************
*** 397,403 ****
                [ymin, ymax, yminp] = get_data_limits (ymin, ymax, yminp, ydat);
              endif
              data{data_idx} = [xdat, ydat]';
!             usingclause{data_idx} = "using ($1):($2)";
            endif
          endif
          if (! (have_newer_gnuplot || isempty (with)))
--- 412,419 ----
                [ymin, ymax, yminp] = get_data_limits (ymin, ymax, yminp, ydat);
              endif
              data{data_idx} = [xdat, ydat]';
!             usingclause{data_idx} = sprintf("using ($1):($2) axes %s%s",
!                                             xaxisloc_using,yaxisloc_using);
            endif
          endif
          if (! (have_newer_gnuplot || isempty (with)))
***************
*** 620,626 ****
      else
        xdir = "noreverse";
      endif
!     fprintf (plot_stream, "set xrange [%g:%g] %s;\n", xlim, xdir);
  
      if (yautoscale && have_data)
        ylim = get_axis_limits (ymin, ymax, yminp, ylogscale);
--- 636,642 ----
      else
        xdir = "noreverse";
      endif
!     fprintf (plot_stream, sprintf("set %srange [%g:%g] %s;\n",xaxisloc, xlim, 
xdir));
  
      if (yautoscale && have_data)
        ylim = get_axis_limits (ymin, ymax, yminp, ylogscale);
***************
*** 633,639 ****
      else
        ydir = "noreverse";
      endif
!     fprintf (plot_stream, "set yrange [%g:%g] %s;\n", ylim, ydir);
  
      if (nd == 3)
        if (zautoscale && have_data)
--- 649,655 ----
      else
        ydir = "noreverse";
      endif
!     fprintf (plot_stream, sprintf("set %srange [%g:%g] %s;\n",yaxisloc, ylim, 
ydir));
  
      if (nd == 3)
        if (zautoscale && have_data)
***************
*** 997,1006 ****
  endfunction
  
  function do_tics (obj, plot_stream)
!   do_tics_1 (obj.xtickmode, obj.xtick, obj.xticklabelmode, obj.xticklabel,
!            "x", plot_stream);
!   do_tics_1 (obj.ytickmode, obj.ytick, obj.yticklabelmode, obj.yticklabel,
!            "y", plot_stream);
    do_tics_1 (obj.ztickmode, obj.ztick, obj.zticklabelmode, obj.zticklabel,
             "z", plot_stream);
  endfunction
--- 1013,1040 ----
  endfunction
  
  function do_tics (obj, plot_stream)
!   if strcmp(obj.xaxislocation,"top")
!     do_tics_1 (obj.xtickmode, obj.xtick, obj.xticklabelmode, obj.xticklabel,
!              "x2", plot_stream);
!     do_tics_1 ("manual", [], obj.xticklabelmode, obj.xticklabel,
!              "x", plot_stream);
!   else
!     do_tics_1 (obj.xtickmode, obj.xtick, obj.xticklabelmode, obj.xticklabel,
!              "x", plot_stream);
!     do_tics_1 ("manual", [], obj.xticklabelmode, obj.xticklabel,
!              "x2", plot_stream);
!   endif
!   if strcmp(obj.yaxislocation,"right")
!     do_tics_1 (obj.ytickmode, obj.ytick, obj.yticklabelmode, obj.yticklabel,
!              "y2", plot_stream);
!     do_tics_1 ("manual", [], obj.yticklabelmode, obj.yticklabel,
!              "y", plot_stream);
!   else
!     do_tics_1 (obj.ytickmode, obj.ytick, obj.yticklabelmode, obj.yticklabel,
!              "y", plot_stream);
!     do_tics_1 ("manual", [], obj.yticklabelmode, obj.yticklabel,
!              "y2", plot_stream);
!   endif
    do_tics_1 (obj.ztickmode, obj.ztick, obj.zticklabelmode, obj.zticklabel,
             "z", plot_stream);
  endfunction
Index: src/graphics.cc
===================================================================
RCS file: /cvs/octave/src/graphics.cc,v
retrieving revision 1.23
diff -c -r1.23 graphics.cc
*** src/graphics.cc     24 Jul 2007 19:02:27 -0000      1.23
--- src/graphics.cc     10 Aug 2007 15:53:58 -0000
***************
*** 975,980 ****
--- 975,982 ----
      xdir ("normal"),
      ydir ("normal"),
      zdir ("normal"),
+     xaxislocation ("bottom"),
+     yaxislocation ("left"),
      view (),
      visible ("on"),
      nextplot ("replace"),
***************
*** 1162,1167 ****
--- 1164,1173 ----
      ydir = val;
    else if (name.compare ("zdir"))
      zdir = val;
+   else if (name.compare ("xaxislocation"))
+     xaxislocation = val;
+   else if (name.compare ("yaxislocation"))
+     yaxislocation = val;
    else if (name.compare ("view"))
      view = val;
    else if (name.compare ("visible"))
***************
*** 1229,1234 ****
--- 1235,1242 ----
    xdir = "normal";
    ydir = "normal";
    zdir = "normal";
+   xaxislocation = "left";
+   yaxislocation = "bottom";
  
    Matrix tview (1, 2, 0.0);
    tview(1) = 90;
***************
*** 1317,1322 ****
--- 1325,1332 ----
    m.assign ("xdir", xdir);
    m.assign ("ydir", ydir);
    m.assign ("zdir", zdir);
+   m.assign ("xaxislocation", xaxislocation);
+   m.assign ("yaxislocation", yaxislocation);
    m.assign ("view", view);
    m.assign ("visible", visible);
    m.assign ("nextplot", nextplot);
***************
*** 1440,1445 ****
--- 1450,1459 ----
      retval = ydir;
    else if (name.compare ("zdir"))
      retval = zdir;
+   else if (name.compare ("xaxislocation"))
+     retval = xaxislocation;
+   else if (name.compare ("yaxislocation"))
+     retval = yaxislocation;
    else if (name.compare ("view"))
      retval = view;
    else if (name.compare ("visible"))
***************
*** 1537,1542 ****
--- 1551,1558 ----
    m["xdir"] = "normal";
    m["ydir"] = "normal";
    m["zdir"] = "normal";
+   m["xaxislocation"] = "bottom";
+   m["yaxislocation"] = "left";
  
    Matrix tview (1, 2, 0.0);
    tview(1) = 90;
Index: src/graphics.h
===================================================================
RCS file: /cvs/octave/src/graphics.h,v
retrieving revision 1.7
diff -c -r1.7 graphics.h
*** src/graphics.h      24 Jul 2007 19:02:27 -0000      1.7
--- src/graphics.h      10 Aug 2007 15:53:58 -0000
***************
*** 1209,1214 ****
--- 1209,1216 ----
      OCTAVE_GRAPHICS_PROPERTY (octave_value, xdir);
      OCTAVE_GRAPHICS_PROPERTY (octave_value, ydir);
      OCTAVE_GRAPHICS_PROPERTY (octave_value, zdir);
+     OCTAVE_GRAPHICS_PROPERTY (octave_value, xaxislocation);
+     OCTAVE_GRAPHICS_PROPERTY (octave_value, yaxislocation);
      OCTAVE_GRAPHICS_PROPERTY (octave_value, view);
      OCTAVE_GRAPHICS_PROPERTY (octave_value, visible);
      OCTAVE_GRAPHICS_PROPERTY (octave_value, nextplot);

reply via email to

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