help-octave
[Top][All Lists]
Advanced

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

multiplot *.m files (again!)


From: Vinayak Dutt
Subject: multiplot *.m files (again!)
Date: Wed, 31 May 95 15:50:26 CDT

Hi Octavers:

Here are a few of my scripts file to support multiplot extensions.
Hope  you will find them useful.

-vinayak

% -----------------------------------------------
% file: bottom_title.m 
% -----------------------------------------------

function bottom_title (text)

% usage: bottom_title (text)
%
% NOTE: this will work only with gnuplot installed with
%       multiplot patch
%
% makes a title with the given text at the bottom of the plot 
% rather than the top.
%

  if (nargin != 1)
    error ("usage: bottom_title (text)");
  endif

  if (isstr (text))
    set top_title
    set title
    command = sprintf ("set bottom_title \"%s\"", text);
    eval (command);
  else
    error ("error: bottom_title: text must be a string");
  endif

endfunction

% -----------------------------------------------
% file: mplot.m 
% -----------------------------------------------

function mplot (...)

# usage: mplot (x, y)
#        mplot (x1, y1, x2, y2, ...)
#        mplot (x, y, fmt)
#
# This is a modified version of plot() command to work with
# multiplot version of gnuplot to plot multiple plots per page.
# This plot version automatically updates the plot position to
# next plot position after making the plot in the given subplot
# position.
#
# See command plot() for the various options to this command
# as this is just mulitplot version of the same command.
#

#
# global variables to keep track of multiplot options
#
  global multiplot_mode 
  global multi_xsize multi_ysize 
  global multi_xn multi_yn
  global multi_xi multi_yi
#
  set nologscale;
  set nopolar;

  plot_int ("plot", all_va_args);
#
# update the plot position
#
  if ( multiplot_mode == 1 )
        if ( multi_xi < multi_xn )
                multi_xi = multi_xi + 1;
        else
                multi_xi = 1;
                if( multi_yi < multi_xn )
                        multi_yi = multi_yi + 1;
                else
                        multi_yi = 1;
                endif;
        endif;
        xo = (multi_xi - 1.0)*multi_xsize;
        yo = (multi_yn - multi_yi)*multi_ysize;
        command = sprintf ("set origin %g,%g", xo,yo);
        eval (command);
  endif;
endfunction

% -----------------------------------------------
% file: multiplot.m 
% -----------------------------------------------

function multiplot (xn,yn)

% usage: multiplot (xn,yn)
%
% NOTE: this will work only with gnuplot installed with
%       multiplot patch
%
%    Sets and resets multiplot mode
%
%    if multiplot(0,0) then it will close multiplot mode and
%    and if arguments are non-zero, then it will set up
%    multiplot mode with xn,yn subplots along x and y axes.
%
% See other plotting commands too.

%
% global variables to keep track of multiplot options
%
  global multiplot_mode 
  global multi_xsize multi_ysize 
  global multi_xn multi_yn
  global multi_xi multi_yi
%
% check calling argument count

  if (nargin != 2)
        error "usage: multiplot (xn,yn)"
  endif

% check for scalar inputs

  if (!(is_scalar(xn) && is_scalar(yn)))
        error ("multiplot: xn and yn have to be scalars");
  endif

  xn = fix(xn);
  yn = fix(yn);

  if ( xn == 0 && yn == 0 )
        set nomultiplot;
        set size 1,1
        set origin 0,0
        multiplot_mode = 0;
        multi_xsize = 1;
        multi_ysize = 1;
        multi_xn = 1;
        multi_yn = 1;
        multi_xi = 1;
        multi_yi = 1;
        return;
  else
        if ( ( xn < 1 ) || ( yn < 1 ) )
                error ("multiplot: xn and yn have to be positive int");
        endif;

        set multiplot;
        xsize = 1.0 ./ xn;
        ysize = 1.0 ./ yn;
        command = sprintf ("set size %g,%g", xsize,ysize);
        eval (command);
        xo = 0.0;
        yo = (yn - 1.0)*ysize;
        command = sprintf ("set origin %g,%g", xo,yo);
        eval (command);
        multiplot_mode = 1;
        multi_xsize = xsize;
        multi_ysize = ysize;
        multi_xn = xn;
        multi_yn = yn;
        multi_xi = 1;
        multi_yi = 1;
  endif;

endfunction

% -----------------------------------------------
% file: oneplot.m 
% -----------------------------------------------

function oneplot ()

% usage: oneplot 
%
% NOTE: this will work only with gnuplot installed with
%       multiplot patch
%
% Switches from multiplot (if in  multiplot mode) to single plot
% mode
%

global multiplot_mode

set nomultiplot;
set size 1,1
set origin 0,0
multiplot_mode = 0;

endfunction

% -----------------------------------------------
% file: plot_border.m 
% -----------------------------------------------

function plot_border (side, ...)

% usage: plot_border (side, ...)
%
% NOTE: this will work only with gnuplot installed with
%       multiplot patch
%
% multiple arguments allowed to specify the sides on which
% the border is shown. allowed strings:
%
% allowed input strings:
%
%  "blank", "BLANK", "b", "B",   --->  No borders displayed
%    "all",   "ALL", "a", "A",   ---> All borders displayed
%  "north", "NORTH", "n", "N",   ---> North Border
%  "south", "SOUTH", "s", "S",   ---> South Border
%   "east",  "EAST", "e", "E",   --->  East Border
%   "west",  "WEST", "w", "W",   --->  West Border
%

  border = 0;
  arg = side;

  if ( ! isstr(arg) )
        error "plot_border: input not a string"
  endif;

% check first argument

  south = strcmp(arg,"south") || strcmp(arg,"SOUTH") ;
  south = south || strcmp(arg,"s") || strcmp(arg,"S") ;
  north = strcmp(arg,"north") || strcmp(arg,"NORTH") ;
  north = north || strcmp(arg,"n") || strcmp(arg,"N") ;
  east  = strcmp(arg,"east") || strcmp(arg,"EAST") ;
  east  =  east || strcmp(arg,"e") || strcmp(arg,"E") ;
  west  = strcmp(arg,"west") || strcmp(arg,"WEST") ;
  west  =  west || strcmp(arg,"w") || strcmp(arg,"W") ;
  all   = strcmp(arg,"all") || strcmp(arg,"ALL") ;
  all   =  all  || strcmp(arg,"a") || strcmp(arg,"A") ;
  blank = strcmp(arg,"blank") || strcmp(arg,"BLANK") ;
  blank = blank || strcmp(arg,"b") || strcmp(arg,"B") ;

  if ( south )
        border = 1;
  elseif ( north )
        border = 4;
  elseif ( east )
        border = 8;
  elseif ( west )
        border = 2;
  elseif ( all )
        border = 15;
  elseif ( blank )
        border = 0;
  endif;

%  check the remaining arguments

  va_start();
  while (--nargin)
          arg = va_arg();
          if ( ! isstr(arg) ) 
                error "plot_border: input not a string"
          endif;

          south = strcmp(arg,"south") || strcmp(arg,"SOUTH") ;
          south = south || strcmp(arg,"s") || strcmp(arg,"S") ;
          north = strcmp(arg,"north") || strcmp(arg,"NORTH") ;
          north = north || strcmp(arg,"n") || strcmp(arg,"N") ;
          east  = strcmp(arg,"east") || strcmp(arg,"EAST") ;
          east  =  east || strcmp(arg,"e") || strcmp(arg,"E") ;
          west  = strcmp(arg,"west") || strcmp(arg,"WEST") ;
          west  =  west || strcmp(arg,"w") || strcmp(arg,"W") ;
          all   = strcmp(arg,"all") || strcmp(arg,"ALL") ;
          all   =  all  || strcmp(arg,"a") || strcmp(arg,"A") ;
          blank = strcmp(arg,"blank") || strcmp(arg,"BLANK") ;
          blank = blank || strcmp(arg,"b") || strcmp(arg,"B") ;

          if ( south )
                border = border + 1;
          elseif ( north )
                border = border + 4;
          elseif ( east )
                border = border + 8;
          elseif ( west )
                border = border + 2;
          elseif ( all )
                border = 15;
          elseif ( blank )
                border = 0;
          endif;
%
  end;

  if ( border == 0 )
        set noborder;
  else
         command = sprintf ("set border %d", border);
        eval (command);
  endif;

endfunction

% -----------------------------------------------
% file: subplot.m 
% -----------------------------------------------

function subplot (xn,yn)

% usage: subplot (xn,yn)
%
% NOTE: this will work only with gnuplot installed with
%       multiplot patch
%
%    Sets subplot position in multiplot mode for next
% plot. The multiplot mode has to be previously initialized
% using multiplot() command. 
%

%
% global variables to keep track of multiplot options
%
  global multiplot_mode 
  global multi_xsize multi_ysize 
  global multi_xn multi_yn
%
% check calling argument count

  if (nargin != 2)
        error "usage: subplot (xn,yn)"
  endif

% check for scalar inputs

  if (!(is_scalar(xn) && is_scalar(yn)))
        error ("subplot: xn and yn have to be scalars");
  endif

  xn = fix(xn);
  yn = fix(yn);

%
  if ( multiplot_mode ~= 1)
        error ("subplot: not in multiplot mode");
  endif;

% get the sub plot location

  if ( xn < 1 || xn > multi_xn || yn < 1 || yn > multi_yn )
        error ("subplot: incorrect xn and yn");
  endif;

  xo = (xn - 1.0)*multi_xsize;
  yo = (yn - yn)*multi_ysize;

  command = sprintf ("set origin %g,%g", xo,yo);
  eval (command);

endfunction

% -----------------------------------------------
% file: top_title.m 
% -----------------------------------------------

function top_title (text)

% usage: top_title (text)
%
% NOTE: this will work only with gnuplot installed with
%       multiplot patch
%
% makes a title with text "text" at the top of the plot 
%

  if (nargin != 1)
    error ("usage: top_title (text)");
  endif

  if (isstr (text))
    set bottom_title
    set title
    command = sprintf ("set top_title \"%s\"", text);
    eval (command);
  else
    error ("error: top_title: text must be a string");
  endif

endfunction

% -----------------------------------------------
% file: zlabel.m 
% -----------------------------------------------

function zlabel (text)

% usage: zlabel (text)
%
% Defines a label for the z-axis of a plot.  The label will appear the
% next time a plot is displayed.
%
% See other plotting commands also.

  if (nargin != 1)
    error ("usage: zlabel (text)");
  endif

  if (isstr (text))
    command = sprintf ("set zlabel \"%s\"", text);
    eval (command);
  else
    error ("error: zlabel: text must be a string");
  endif

endfunction



reply via email to

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