help-octave
[Top][All Lists]
Advanced

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

Re: Unidentified subject!


From: Paul Kienzle
Subject: Re: Unidentified subject!
Date: Mon, 19 Jun 2000 11:40:10 +0100 (BST)

From: address@hidden
>Hi,
>
>I am looking for a method  to plot a curve in 3-dimensions in octave (and then 
>print
>the file). I have the (xyz)-co-ordinates of N points on the curve in the form 
>of 
>three vectors xval, yval and zval, each with N elements. 
>
>It's also not clear to me how to annotate the axes, change the viewpoint of 
>the plot 
>etc. Do you have some idea on how to do this ?
>
>Regards,
>
>Constantine Frangos.
>Constantine Frangos
>Professor
>Dept. of Statistics
>The Rand Afrikaans University
>P O Box 524
>Auckland Park 2006
>Johannesburg
>South Africa
>
>Tel: +27-11-489-2452
>Fax: +27-11-489-2832
>e-mail: address@hidden
>

Here is the result of some cut/paste/modify operations on files in the
scripts/plot directory to make plot work in 3D.  Save as plot3.m and
__plt3__.m in your octave path.  Call as plot3(x,y,z,fmt).  I've used
the interface documented for matlab.

Paul Kienzle
address@hidden

plot3.m:
## Copyright (C) 1996 John W. Eaton
##
## This file was part of Octave.
##
## Octave is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.
##
## Octave 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 Octave; see the file COPYING.  If not, write to the Free
## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
## 02111-1307, USA.

## usage: plot3 (x, y, z)
##        plot3 (x1, y1, z1, x2, y2, z2, ...)
##        plot3 (x, y, z, fmt)
##
## If all arguments are vectors of the same length, a single line is
## drawn in three space.
##
## If all arguments are matrices, each column is drawn as a separate
## line. In this case, all matrices must have the same number of rows
## and columns and no attempt is made to transpose the arguments to make
## the number of rows match.
##
## To see possible options for FMT please see __pltopt__.
##
## Example
##
##    z = [0:0.05:5];
##    plot3(cos(2*pi*z), sin(2*pi*z), z, ";helix;");

function plot3(...)

  hold_state = ishold ();
  
  unwind_protect

    x_set = 0;
    y_set = 0;
    z_set = 0;
    
    ## Gather arguments, decode format, and plot lines.
    
    while (nargin-- > 0)
      
      new = va_arg ();
      
      if (isstr (new))
        if (! z_set)
          error ("plot3: needs x, y, z");
        endif
        fmt = __pltopt__ ("plot3", new);
        __plt3__(x, y, z, fmt);
        hold on;
        x_set = 0;
        y_set = 0;
        z_set = 0;
      elseif (!x_set)
        x = new;
        x_set = 1;
      elseif (!y_set)
        y = new;
        y_set = 1;
      elseif (!z_set)
        z = new;
        z_set = 1;
      else
        __plt3__ (x, y, z, "");
        hold on;
        x = new;
        y_set = 0;
        z_set = 0;
      endif
 
### Code copied from __plt__; don't know if it is needed     
###
###   ## Something fishy is going on.  I don't think this should be
###   ## necessary, but without it, sometimes not all the lines from a
###   ## given plot command appear on the screen.  Even with it, the
###   ## delay might not be long enough for some systems...
###     
###   usleep (1e5);
      
    endwhile
    
    ## Handle last plot.

    if  (z_set)
      __plt3__ (x, y, z, "");
    elseif (x_set)
      error ("plot3: needs x, y, z");
    endif
    
  unwind_protect_cleanup
    
    if (! hold_state)
      hold off;
    endif
    
  end_unwind_protect

endfunction

__plt3__.m:
## Copyright (C) 1996 John W. Eaton
##
## This file was part of Octave.
##
## Octave is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.
##
## Octave 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 Octave; see the file COPYING.  If not, write to the Free
## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
## 02111-1307, USA.

function __plt3__ (x, y, z, fmt)

  [rx, cx] = size(x);
  [ry, cy] = size(y);
  [rz, cz] = size(z);

  if all([rx, ry, rz, cx, cy, cz] != 1)
    if (cx != cy || cx != cz)
      error("plot3: x, y, and z must have the same number of columns");
    endif
  else
    if cx != 1, x = x.'; endif
    if cy != 1, y = y.'; endif
    if cz != 1, z = z.'; endif
    [rx, cx] = size(x);
    [ry, cy] = size(y);
    [rz, cz] = size(z);
  endif

  if (rx != ry || rx != rz)
    error("plot3: x, y, and z must have the same length");
  endif

  unwind_protect
    gset parametric;
    for i=1:cx
      tmp = [x(:,i), y(:,i), z(:,i)];
      eval(sprintf("gsplot tmp %s", fmt));
    endfor
  unwind_protect_cleanup
    gset noparametric; 
  end_unwind_protect
endfunction



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

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



reply via email to

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