Alternative to gset nokey;

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Alternative to gset nokey;

Joe Koski
Now that I've installed octave-2.1.69, I'm getting all sorts of warnings
like

warning: in graw near line 28, column 1:
warning: graw is deprecated and will be removed from a future
warning: version of Octave.
warning: You should use the higher-level plot functions
warning: ("plot", "mesh", "semilogx", etc.) instead
warning: of the low-level plotting commands.
warning: If you absolutely must use this function, use the
warning: internal version __gnuplot_raw__ instead.
warning: gset is deprecated and will be removed from a future
warning: version of Octave.
warning: You should use the higher-level plot functions
warning: ("plot", "mesh", "semilogx", etc.) instead
warning: of the low-level plotting commands.
warning: If you absolutely must use this function, use the
warning: internal version __gnuplot_set__ instead.

in the middle of my output. Annoying, but OK, I see the point. What is the
now proper equivalent to gset nokey; ?

Joe




-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

Re: Alternative to gset nokey;

Dmitri A. Sergatskov
Joe Koski wrote:
> Now that I've installed octave-2.1.69, I'm getting all sorts of warnings
...
> warning: gset is deprecated and will be removed from a future
> warning: version of Octave.
> warning: You should use the higher-level plot functions
> warning: ("plot", "mesh", "semilogx", etc.) instead
...
> in the middle of my output. Annoying, but OK, I see the point. What is the
> now proper equivalent to gset nokey; ?
>

plot (x,y,";;")

> Joe
>

Regards,

Dmitri.



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

Re: Alternative to gset nokey;

John W. Eaton-6
On 14-Apr-2005, Dmitri A. Sergatskov <[hidden email]> wrote:

| Joe Koski wrote:
| > Now that I've installed octave-2.1.69, I'm getting all sorts of warnings
| ...
| > warning: gset is deprecated and will be removed from a future
| > warning: version of Octave.
| > warning: You should use the higher-level plot functions
| > warning: ("plot", "mesh", "semilogx", etc.) instead
| ...
| > in the middle of my output. Annoying, but OK, I see the point. What is the
| > now proper equivalent to gset nokey; ?
| >
|
| plot (x,y,";;")

Or, if you are aiming for compatibility, you can use

  legend ('off');
  plot (x, y);

Currently, legend is part of Octave-forge.

jwe



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

Re: Alternative to gset nokey;

Joe Koski
on 4/14/05 2:46 PM, John W. Eaton at [hidden email] wrote:

> On 14-Apr-2005, Dmitri A. Sergatskov <[hidden email]> wrote:
>
> | Joe Koski wrote:
> | > Now that I've installed octave-2.1.69, I'm getting all sorts of warnings
> | ...
> | > warning: gset is deprecated and will be removed from a future
> | > warning: version of Octave.
> | > warning: You should use the higher-level plot functions
> | > warning: ("plot", "mesh", "semilogx", etc.) instead
> | ...
> | > in the middle of my output. Annoying, but OK, I see the point. What is the
> | > now proper equivalent to gset nokey; ?
> | >
> |
> | plot (x,y,";;")
>
> Or, if you are aiming for compatibility, you can use
>
>   legend ('off');
>   plot (x, y);
>
> Currently, legend is part of Octave-forge.
>
> jwe

John, Dmitri,

Thanks for the help; that got me going in the right direction. I elected to
go the legend('off') route, but that led me to some other problems.

When I use legend.m to actually write a legend with my own text strings, the
graw and gset warnings reappear. In looking at the legend.m routine that
comes with octave-forge-2004.11.16, it has a dozen or so mentions of gset
and graw that are apparently triggering the warnings.

I think I know how to rewrite legend.m to use __gnuplot_set__ in place of
gset. I've already done that successfully in another routine, my local
version of figure.m that sets font and font size. Is __gnuplot_set__ the
correct approach, or is there a better, more forward looking way?

In legend.m graw appears as

  tmpfilename=tmpnam;
  command=["save \"",tmpfilename,"\"\n"];
  graw(command);

and as

  new_plot = [new_plot, "\n"];
  graw(new_plot);

What is the correct replacement for this usage of graw? __gnuplot_set__ does
not seem appropriate here.

If I get something working, I'll send it to the bug list for possible
inclusion. Alternatively, does someone else have a patched version of
legend.m already available?

Joe




-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

Re: Alternative to gset nokey;

Dmitri A. Sergatskov
Joe Koski wrote:

> I think I know how to rewrite legend.m to use __gnuplot_set__ in place of
> gset. I've already done that successfully in another routine, my local
> version of figure.m that sets font and font size. Is __gnuplot_set__ the
> correct approach, or is there a better, more forward looking way?
>

I actually converted all octave-forge plotting routines to the new syntax.
__gnuplot_set__ should/will be eventually replaced by __gnuplot_raw__(),
but at the moment there are some complications, so __gnuplot_set__
will be here for a while.

The diff is at
ftp://coffee.phys.unm.edu/pub/dima/octave/plot.diff.bz2

Unfortunately new version of legend.m has a typo.
Please find and replace
__gnuplot_raw__ new_plot

with

__gnuplot_raw__(new_plot)

(Perhaps there are other problems, but it works for me.)

Regards,
Dmitri.
--



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

Legend.m (Was: Alternative to gset nokey;)

Dmitri A. Sergatskov
In reply to this post by Joe Koski
Please find attached a version of legend.m modified to
use new __gnuplot_... interface.
Also attached is the diff against current (2005-04-15)
version from cvs.

Sincerely,
Dmitri.
--

*** octave-forge/main/plot/legend.m 2005-02-25 09:17:45.000000000 -0700
--- /tumbleweed/dima/src/octave-forge.2005.04.12/main/plot/legend.m 2005-04-15 11:01:35.000000000 -0600
***************
*** 106,128 ****
      _replot = 1;
      switch _str
        case {"off", "hide"}
!         gset nokey;
        case "show"
! gset key;
        case "boxon"
! gset key box;
        case "boxoff"
! gset key nobox;
        case "left"
!         gset key Right noreverse;
        case "right"
!         gset key Left reverse;
        otherwise
  _replot = 0;
      endswitch
      if _replot
        if automatic_replot
!         replot
        endif
        return;
      endif
--- 106,128 ----
      _replot = 1;
      switch _str
        case {"off", "hide"}
!         __gnuplot_raw__ ("set nokey;\n")
        case "show"
! __gnuplot_raw__ ("set  key;\n")
        case "boxon"
! __gnuplot_raw__ ("set  key box;\n")
        case "boxoff"
! __gnuplot_raw__ ("set  key nobox;\n")
        case "left"
!         __gnuplot_raw__ ("set  key Right noreverse;\n")
        case "right"
!         __gnuplot_raw__ ("set  key Left reverse;\n")
        otherwise
  _replot = 0;
      endswitch
      if _replot
        if automatic_replot
!         __gnuplot_replot__
        endif
        return;
      endif
***************
*** 148,155 ****
    ## Get the original plotting command
   
    tmpfilename=tmpnam;
!   command=["save \"",tmpfilename,"\"\n"];
!   graw(command);
 
    awk_prog= \
        "BEGIN { \
--- 148,154 ----
    ## Get the original plotting command
   
    tmpfilename=tmpnam;
!   __gnuplot_raw__ (["save \"",tmpfilename,"\"\n"]);
 
    awk_prog= \
        "BEGIN { \
***************
*** 264,270 ****
    ## Create a new plotting command
 
    new_plot = [new_plot, "\n"];  
!   graw(new_plot);
 
    ## Check for the last argument if we don't already get it
   
--- 263,269 ----
    ## Create a new plotting command
 
    new_plot = [new_plot, "\n"];  
!   __gnuplot_raw__ (new_plot)
 
    ## Check for the last argument if we don't already get it
   
***************
*** 280,311 ****
    if ((isscalar (pos_leg)) && (isreal(pos_leg)))
      switch (pos_leg)
        case 1
!         gset key right top;
        case 2
!         gset key left top;
        case 3
!         gset key left bottom;
        case 4
!         gset key right bottom;
        case -1
!         gset key right top outside;
        case -2
!         gset key right bottom outside;
        case -3
!         gset key below;
        otherwise
          warning ("incorrect pos");
      endswitch;
    elseif (isvector (pos_leg)) && (length (pos_leg) == 2) && \
          (all(isreal(pos_leg)))
!     eval (sprintf ("gset key %e, %e", pos_leg(1), pos_leg(2)));
    else
      warning ("pos must be a scalar");
    endif;
 
    ## Regenerate the plot
   
!   replot;
   
  endfunction;
 
--- 279,310 ----
    if ((isscalar (pos_leg)) && (isreal(pos_leg)))
      switch (pos_leg)
        case 1
!         __gnuplot_raw__ ("set  key right top;\n")
        case 2
!         __gnuplot_raw__ ("set  key left top;\n")
        case 3
!         __gnuplot_raw__ ("set  key left bottom;\n")
        case 4
!         __gnuplot_raw__ ("set  key right bottom;\n")
        case -1
!         __gnuplot_raw__ ("set  key right top outside;\n")
        case -2
!         __gnuplot_raw__ ("set  key right bottom outside;\n")
        case -3
!         __gnuplot_raw__ ("set  key below;\n")
        otherwise
          warning ("incorrect pos");
      endswitch;
    elseif (isvector (pos_leg)) && (length (pos_leg) == 2) && \
          (all(isreal(pos_leg)))
!     eval (sprintf ("__gnuplot_raw__ (\"set key %e, %e\")", pos_leg(1), pos_leg(2)));
    else
      warning ("pos must be a scalar");
    endif;
 
    ## Regenerate the plot
   
!   __gnuplot_replot__
   
  endfunction;
 

## Copyright (C) 2001 Laurent Mazet
##
## This program is free software; it is distributed in the hope that it
## will be useful, but WITHOUT ANY WARRANTY; without even the implied
## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
## the GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this file; see the file COPYING.  If not, write to the
## Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
## 02111-1307, USA.

## -*- texinfo -*-
## @deftypefn {Function File} {} legend (@var{st1}, @var{st2}, @var{st3}, @var{...})
## @deftypefnx {Function File} {} legend (@var{st1}, @var{st2}, @var{st3}, @var{...}, @var{pos})
## @deftypefnx {Function File} {} legend (@var{matstr})
## @deftypefnx {Function File} {} legend (@var{matstr}, @var{pos})
## @deftypefnx {Function File} {} legend (@var{cell})
## @deftypefnx {Function File} {} legend (@var{cell}, @var{pos})
## @deftypefnx {Function File} {} legend ('@var{func}')
##
## Legend puts a legend on the current plot using the specified strings
## as labels. Use independant strings (@var{st1}, @var{st2}, @var{st3}...), a
## matrix of strings (@var{matstr}), or a cell array of strings (@var{cell}) to
## specify legends. Legend works on line graphs, bar graphs, etc...
## Be sure to call plot before calling legend.
##
## @var{pos} optionally  places the legend in the specified location:
##
## @multitable @columnfractions 0.1 0.1 0.8
## @item @tab 0 @tab
##   Don't move the legend box (default)
## @item @tab 1 @tab
##   Upper right-hand corner
## @item @tab 2 @tab
##   Upper left-hand corner
## @item @tab 3 @tab
##   Lower left-hand corner
## @item @tab 4 @tab
##   Lower right-hand corner
## @item @tab -1 @tab
##   To the top right of the plot
## @item @tab -2 @tab
##   To the bottom right of the plot
## @item @tab -3 @tab
##   To the bottom of the plot
## @item @tab [@var{x}, @var{y}] @tab
##   To the arbitrary postion in plot [@var{x}, @var{y}]
## @end multitable
##
## Some specific functions are directely avaliable using @var{func}:
##
## @table @code
## @item show
##   Show legends from the plot
## @item hide
## @itemx off
##   Hide legends from the plot
## @item boxon
##   Draw a box around legends
## @item boxoff
##   Withdraw the box around legends
## @item left
##   Text is to the left of the keys
## @item right
##   Text is to the right of the keys
## @end table
##
## REQUIRES: unix piping functionality, grep, sed and awk
## @end deftypefn

## 2001-03-31 Paul Kienzle
##   * use tmpnam for temporary file name; unlink to remove
## 2001-09-28 Paul Söderlind <[hidden email]>
##   * add a pause after save request to give gnuplot time to write the file
##   * add comment to call plot before legend.
## 2002-09-18 Paul Kienzle
##   * make the pause check every .1 seconds
## 2003-04-1 Laurent Mazet
##   * add new functions (boxon, boxoff...)
##   * rebuild help message
## 2003-06-12 Quentin Spencer
##   * add support for input in cell array format

## PKG_ADD mark_as_command legend
function legend (varargin)

  ## Use the following for 2.1.39 and below
  # varargin = list(varargin, all_va_args);
  args = nargin; # silliness: nargin is now a function

  ## Data type

  data_type = 0;
  va_arg_cnt = 1;

  str = "";
  if (args > 0)
    str = nth (varargin, va_arg_cnt++);
  endif;
     
  ## Test for strings

  if (isstr(str)) && (args == 1)
    _str = tolower(deblank(str));
    _replot = 1;
    switch _str
      case {"off", "hide"}
        __gnuplot_raw__ ("set nokey;\n")
      case "show"
        __gnuplot_raw__ ("set  key;\n")
      case "boxon"
        __gnuplot_raw__ ("set  key box;\n")
      case "boxoff"
        __gnuplot_raw__ ("set  key nobox;\n")
      case "left"
        __gnuplot_raw__ ("set  key Right noreverse;\n")
      case "right"
        __gnuplot_raw__ ("set  key Left reverse;\n")
      otherwise
        _replot = 0;
    endswitch
    if _replot
      if automatic_replot
        __gnuplot_replot__
      endif
      return;
    endif
  endif

  ## Test for data type (0 -> list of string, 1 -> array of string)

  if (length(str) != 0) && (isstr(str(1,:))) && (rows(str) != 1) || iscell(str)
    data_type = 1;
    va_arg_cnt = 1;

    if (iscell(str))
      data = nth (varargin, va_arg_cnt++);
    else
      data = cellstr( nth (varargin, va_arg_cnt++));
    endif
    nb_data = length(data);
    args--;
  endif;

  pos_leg = 1;
 
  ## Get the original plotting command
 
  tmpfilename=tmpnam;
  __gnuplot_raw__ (["save \"",tmpfilename,"\"\n"]);

  awk_prog= \
      "BEGIN { \
        dq = 0; \
        format = \"%s\\n\"; \
       } \
       NF != 0 { \
        for (i=1;i<=NF;i++) { \
         if ($(i) == \"\\\"\") { \
          if (dp == 0) { \
           dp = 1; \
           if ($(i+1) != \"\\\"\") { \
            i++; \
            printf (\"%s\", $(i)); \
           } \
          format = \" %s\"; \
          } else { \
           dp = 0; \
           format = \"%s\\n\"; \
           printf (\"\\n\"); \
          } \
         } else { \
          printf (format, $(i)); \
         } \
        } \
       }";
           
  shell_cmd=["grep \"^", gnuplot_command_plot, " \" '", tmpfilename, "' | ", \
             "sed -e 's/,/ , /g' -e 's/\"/ \" /g'", " | ", \
             "awk '", awk_prog, "'"];

  # wait for the file to appear
  attempt=0;
  while (isempty(stat(tmpfilename)))
    if (++attempt > 20) error("gnuplot is not responding"); endif
    usleep(1e5);
  end
  plot_cmd = split(system(shell_cmd),"\n");

  if (~length(deblank(plot_cmd(rows(plot_cmd), :))))
    plot_cmd = plot_cmd ([1:rows(plot_cmd)-1],:);
  endif;
  unlink(tmpfilename);
 
  ## Look for the number of graph

  nb_graph = 0;
  i = 0;
  while (i++ < rows(plot_cmd))
    line = deblank(plot_cmd(i,:));
    if ((strcmp(line, gnuplot_command_plot)) || (strcmp(line, ",")))
      nb_graph++;
    endif;
  endwhile;

  ## Change the legend of each graph
 
  new_plot = [];
  if (data_type == 0)
    va_arg_cnt = 1;

  endif;
  fig = 0;
  i = 1;
  while (fig < nb_graph)

    ## Get the legend string

    if (((data_type == 0) && (args <= 0)) || \
        ((data_type == 1) && (fig >= nb_data)))
      leg = "\"\"";
    else
      if (data_type == 0)
        leg = nth (varargin, va_arg_cnt++);
        args--;
      else
        leg = data{fig+1};
      endif;
      if (!isstr(leg))
        pos_leg = leg;
        leg = "\"\"";
      elseif (length(deblank(leg)) == 0)
        leg = "\"\"";
      else
        leg=["\"" leg "\""];
      endif;
    endif;

    ## look for the end of the graph command i.e. ","

    new_line = [deblank(plot_cmd(i++,:)), " \"", \
                strrep(deblank(plot_cmd(i++,:)), "'", "") "\""];
    while ((i <= rows(plot_cmd)) && (!strcmp(deblank(plot_cmd(i,:)), ",")))
      if (strcmp(deblank(plot_cmd(i,:)), gnuplot_command_title))
        new_line = [new_line, " ", gnuplot_command_title, " ", leg];
        i++;
      else
        new_line = [new_line, " ", deblank(plot_cmd(i,:))];
      endif;
      i++;
    endwhile;

    if (length(new_plot))
      new_plot = [ new_plot, new_line];
    else
      new_plot = new_line;
    endif;
   
    fig++;
  endwhile;

  ## Create a new plotting command

  new_plot = [new_plot, "\n"];  
  __gnuplot_raw__ (new_plot)

  ## Check for the last argument if we don't already get it
 
  while (args-- > 0)
    pos_leg = nth (varargin, va_arg_cnt++) ;
    if (isstr(pos_leg))
      pos_leg = 0;
    endif;
  endwhile;
 
  ## Change the legend position

  if ((isscalar (pos_leg)) && (isreal(pos_leg)))
    switch (pos_leg)
      case 1
        __gnuplot_raw__ ("set  key right top;\n")
      case 2
        __gnuplot_raw__ ("set  key left top;\n")
      case 3
        __gnuplot_raw__ ("set  key left bottom;\n")
      case 4
        __gnuplot_raw__ ("set  key right bottom;\n")
      case -1
        __gnuplot_raw__ ("set  key right top outside;\n")
      case -2
        __gnuplot_raw__ ("set  key right bottom outside;\n")
      case -3
        __gnuplot_raw__ ("set  key below;\n")
      otherwise
        warning ("incorrect pos");
    endswitch;
  elseif (isvector (pos_leg)) && (length (pos_leg) == 2) && \
        (all(isreal(pos_leg)))
    eval (sprintf ("__gnuplot_raw__ (\"set key %e, %e\")", pos_leg(1), pos_leg(2)));
  else
    warning ("pos must be a scalar");
  endif;

  ## Regenerate the plot
 
  __gnuplot_replot__
 
endfunction;

%!demo
%! close all;
%! plot(1:10, 1:10);
%! title("a very long label can sometimes cause problems");
%! legend({"hello world"}, -1)

%!demo
%! close all;
%! labels = {};
%! for i = 1:10
%!     plot(1:100, rand(1)*10 + rand(100,1)); hold on;
%!     labels = {labels{:}, strcat("Signal ", num2str(i))};
%! endfor; hold off;
%! title("Signals with random offset and uniform noise")
%! xlabel("Sample Nr [k]"); ylabel("Amplitude [V]");
%! legend(labels, -1)
%! legend("boxon")

Reply | Threaded
Open this post in threaded view
|

Re: Legend.m (Was: Alternative to gset nokey;)

Joe Koski
on 4/15/05 11:13 AM, Dmitri A. Sergatskov at [hidden email] wrote:

> Please find attached a version of legend.m modified to
> use new __gnuplot_... interface.
> Also attached is the diff against current (2005-04-15)
> version from cvs.
>
> Sincerely,
> Dmitri.

Thanks, Dmitri. I managed to put together a working legend.m by editing the
earlier patch that you sent. That eliminates the gset and graw warnings for
my most commonly used routines.

A general question: Most of the first patches that Dmitri sent use a syntax
of the type

  __gnuplot_set__  nokey

instead of

  __gnuplot_set__("nokey");

which is what my octave-2.1.69 on a Mac accepts. On which machines, and at
what times can the parentheses and quotes be omitted? I've seen examples in
the online index (and been confused by them) with the same format.

There is one other routine, print.m, that I would also like to fix. The
patch that Dmitri sent for print.m yeilds the __gnuplot_set__  nokey type of
syntax, and my octave seems to choke when it sees that. Some of the
eval(sprintf(.... Statements in print.m are true syntactical nightmares with
three levels of quote marks and two levels of parentheses. I tried fixing
print.m, but I doubt that I have everything matched correctly. I'll keep
hacking at it, but if someone has a correctly patched print.m, I'd like to
have it. Thanks.

Joe






-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

Re: Legend.m (Was: Alternative to gset nokey;)

Dmitri A. Sergatskov
Joe Koski wrote:

>
>   __gnuplot_set__  nokey
>
> instead of
>
>   __gnuplot_set__("nokey");
>

In original patch it was

__gnuplot_set__ nokey

later, I changed that to

__gnuplot_raw__ ("set nokey")

Dmitri.
--



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

Re: Legend.m (Was: Alternative to gset nokey;)

Dmitri A. Sergatskov
In reply to this post by Joe Koski
You may also want to look at the thread:

http://www.octave.org/octave-lists/archive/octave-maintainers.2005/msg00250.html

Dmitri.
--



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------